factory_boy icon indicating copy to clipboard operation
factory_boy copied to clipboard

Explicitly export values on factory namespace

Open DavidCain opened this issue 10 months ago • 4 comments

Now that factory-boy exports its types, mypy will fail in strict mode if using the factory namespace. Specifically, --no-implicit-reexport flags references to factory.Factory (and other similar values) as being implicitly exported:

$ mypy --strict test.py
test.py:1:1: error: Module "factory" does not explicitly export attribute "Factory"  [attr-defined]
    from factory import Factory
    ^

We can instead explicitly export these objects. As a benefit, anybody who uses the ill-advised from factory import * will now at least no longer have __author__ and such pollute their namespace.

https://mypy.readthedocs.io/en/stable/config_file.html#confval-implicit_reexport

DavidCain avatar Feb 04 '25 15:02 DavidCain

Just a mild bump that this feels like a useful thing to get in 🙇

samuelhwilliams avatar Apr 01 '25 13:04 samuelhwilliams

@rbarrois - any thoughts about this proposed change?

DavidCain avatar Apr 01 '25 14:04 DavidCain

@rbarrois can we have it merged? Everyone was using namespaces as factory...

sshishov avatar Jun 10 '25 19:06 sshishov

This would be really nice to get merged. It seems like a fairly low risk change since it only updates the __all__ of the top level factory module but it will take care of a lot of false positive import errors from type checkers.

trogers8080 avatar Nov 04 '25 23:11 trogers8080