From 13d219d973fd2b841a7dee4a24d5f1247517858b Mon Sep 17 00:00:00 2001 From: David Cain Date: Tue, 4 Feb 2025 07:15:59 -0800 Subject: [PATCH] Explicitly export values on factory namespace 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. 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 --- docs/changelog.rst | 2 +- factory/__init__.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7fc509d3..d2211f3a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,7 +6,7 @@ ChangeLog 3.3.4 (unreleased) ------------------ -- Nothing changed yet. +- Values on the `factory` namespace are now explicitly exported. 3.3.3 (2025-02-03) diff --git a/factory/__init__.py b/factory/__init__.py index 62042a2a..093c558c 100644 --- a/factory/__init__.py +++ b/factory/__init__.py @@ -54,22 +54,86 @@ stub_batch, ) + +__all__ = [ + "BUILD_STRATEGY", + "BaseDictFactory", + "BaseListFactory", + "CREATE_STRATEGY", + "ContainerAttribute", + "Dict", + "DictFactory", + "Factory", + "FactoryError", + "Faker", + "Iterator", + "LazyAttribute", + "LazyAttributeSequence", + "LazyFunction", + "List", + "ListFactory", + "Maybe", + "PostGeneration", + "PostGenerationMethodCall", + "RelatedFactory", + "RelatedFactoryList", + "STUB_STRATEGY", + "SelfAttribute", + "Sequence", + "StubFactory", + "SubFactory", + "Trait", + "Transformer", + "build", + "build_batch", + "container_attribute", + "create", + "create_batch", + "debug", + "generate", + "generate_batch", + "iterator", + "lazy_attribute", + "lazy_attribute_sequence", + "make_factory", + "post_generation", + "sequence", + "simple_generate", + "simple_generate_batch", + "stub", + "stub_batch", + "use_strategy", +] + + try: from . import alchemy except ImportError: pass +else: + __all__.append("alchemy") + try: from . import django except ImportError: pass +else: + __all__.append("django") + try: from . import mogo except ImportError: pass +else: + __all__.append("mogo") + try: from . import mongoengine except ImportError: pass +else: + __all__.append("mongoengine") + __author__ = 'Raphaƫl Barrois ' __version__ = importlib.metadata.version("factory_boy")