Git Product home page Git Product logo

types-factory-boy's Introduction

Typing stubs for factory-boy

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.

Installation

pip install types-factory-boy

types-factory-boy's People

Contributors

youtux avatar alessio-b2c2 avatar dependabot[bot] avatar pre-commit-ci[bot] avatar jimmylai avatar last-partizan avatar hans-d avatar jakobgm avatar

Stargazers

Pascal Fouque avatar Francisco Boni avatar João Sousa avatar Marco Martinez avatar Carlo Bertini avatar Alex Sheluchin avatar Nick avatar Ivailo Karamanolev avatar  avatar  avatar  avatar Louis L avatar Anton Ruhlov avatar  avatar Chris Tapper avatar  avatar David Baumgold avatar

Watchers

 avatar Guillaume Andreu Sabater avatar  avatar

types-factory-boy's Issues

Issue: FactoryMetaClass does not define __getitem__

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?

Not working with `create(...)` and `create_batch` somehow

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

mypy complains that "Need type annotation" for Faker fields

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.