refactor: move non-circular deferred imports to top-level, noqa circular ones

This commit is contained in:
Mike 2026-05-22 16:22:29 -07:00
parent 39b4a46cb8
commit 8339249381
5 changed files with 17 additions and 17 deletions

View file

@ -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)

View file

@ -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):

View file

@ -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])

View file

@ -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"))

View file

@ -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)