From 833924938190213a74c177a02fc1705f4450e06c Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 22 May 2026 16:22:29 -0700 Subject: [PATCH] refactor: move non-circular deferred imports to top-level, noqa circular ones --- eav/__init__.py | 4 ++-- eav/decorators.py | 7 ++++--- eav/logic/managers.py | 2 +- eav/validators.py | 2 +- manage.py | 19 +++++++++---------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/eav/__init__.py b/eav/__init__.py index af09550..5d464b0 100644 --- a/eav/__init__.py +++ b/eav/__init__.py @@ -1,10 +1,10 @@ def register(model_cls, config_cls=None): - from eav.registry import Registry + from eav.registry import Registry # noqa: PLC0415 Registry.register(model_cls, config_cls) def unregister(model_cls): - from eav.registry import Registry + from eav.registry import Registry # noqa: PLC0415 Registry.unregister(model_cls) diff --git a/eav/decorators.py b/eav/decorators.py index 580af6c..e00cfd9 100644 --- a/eav/decorators.py +++ b/eav/decorators.py @@ -3,6 +3,10 @@ This module contains pure wrapper functions used as decorators. Functions in this module should be simple and not involve complex logic. """ +from django.db.models import Model + +from eav import register + def register_eav(**kwargs): """ @@ -13,9 +17,6 @@ def register_eav(**kwargs): class Author(models.Model): pass """ - from django.db.models import Model - - from eav import register def _model_eav_wrapper(model_class): if not issubclass(model_class, Model): diff --git a/eav/logic/managers.py b/eav/logic/managers.py index f80a26a..3130362 100644 --- a/eav/logic/managers.py +++ b/eav/logic/managers.py @@ -86,7 +86,7 @@ class ValueManager(models.Manager): Returns: Value: The instance matching the provided keys. """ - from eav.models import Attribute + from eav.models import Attribute # noqa: PLC0415 attribute = Attribute.objects.get(name=attribute[0], slug=attribute[1]) diff --git a/eav/validators.py b/eav/validators.py index 4518021..01543a9 100644 --- a/eav/validators.py +++ b/eav/validators.py @@ -83,7 +83,7 @@ def validate_enum(value): Raises ``ValidationError`` unless *value* is a saved :class:`~eav.models.EnumValue` model instance. """ - from eav.models import EnumValue + from eav.models import EnumValue # noqa: PLC0415 if isinstance(value, EnumValue) and not value.pk: raise ValidationError(_("EnumValue has not been saved yet")) diff --git a/manage.py b/manage.py index 55f825f..94397ee 100755 --- a/manage.py +++ b/manage.py @@ -3,6 +3,15 @@ import os import sys +try: + from django.core import management +except ImportError as err: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + + "available on your PYTHONPATH environment variable? Did you " + + "forget to activate a virtual environment?", + ) from err + def main() -> None: """ @@ -14,16 +23,6 @@ def main() -> None: 3. Executes any given command """ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") - - try: - from django.core import management - except ImportError as err: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - + "available on your PYTHONPATH environment variable? Did you " - + "forget to activate a virtual environment?", - ) from err - management.execute_from_command_line(sys.argv)