This is a PEP 561 type stub package for the factory-boy
package.
It can be used by type-checking tools like mypy, PyCharm, pytype etc. to check code
that uses factory-boy
.
pip install types-factory-boy
Type stubs for factory-boy
License: MIT License
I'm not sure if I'm using this wrong but when I define a factory such as:
class UserFactory(factory.django.DjangoModelFactory[User]):
class Meta:
model = User
I get the following error:
Class 'FactoryMetaClass' does not define '__getitem__', so the '[]' operator cannot be used on its instances
I understand why the error occurs, but I'm not sure what the intended solution is. Since DjangoModelFactory is generic in the stubs, what's the intended usage if DjangoModelFactory isn't actually able to support getitem? Should I monkeypatch FactoryMetaClass?
I am getting a lot of this errors:
error: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "create" [attr-defined]
error: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "create_batch" [attr-defined]
when apply the type to DjangoModelFactory
I have factories like:
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
username = factory.Sequence(lambda n: f"{_faker.user_name()}_{n:08}")
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
email = factory.Faker("ascii_safe_email")
with mypy 0.982 I get:
$ mypy --show-error-codes .
blog/factories.py:28: error: Need type annotation for "first_name" [var-annotated]
blog/factories.py:29: error: Need type annotation for "last_name" [var-annotated]
blog/factories.py:30: error: Need type annotation for "email" [var-annotated]
so all the factory.Faker
fields have a problem
I can guess this is probably due to the way factory.Faker
itself is implemented - the type of the faker depends on the value of the string arg and there's no way for type info from faker
itself to flow through that interface.
I guess the only way for that to work would be to tediously define an @overload
with Literal[<method name>]
for each faker method? Maybe that's not even possible either.
Currently, if I use the factory class directly to create an object, it's type hinted as the factory class:
user = UserFactory()
reveal_type(user) # UserFactory
type(user) # User
I think this might be because the return value of BaseFactory.__new__
is annotated with Self
rather than T
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.