Fixing 'Import cycle from Django settings module prevents type inference' #2097
Replies: 2 comments 8 replies
-
I'm honestly unsure why this error is emitted by the plugin in the first place. Deserves to be investigated if it's a remnant of an old mypy crash fix, or if it leads to any other issue(s). I'm suspecting that we might be able to remove the code yielding the error |
Beta Was this translation helpful? Give feedback.
-
I'm seeing this error as well after upgrading to 5.0.0, in some cases for extremely obvious variables where it should be trivial to infer the type. For example: # settings.py
DEFAULT_FROM_EMAIL = f'Company Name <[email protected]>' $ mypy .
# error: Import cycle from Django settings module prevents type inference for 'DEFAULT_FROM_EMAIL' [misc] If I explicitly add the type hint, it works # settings.py
DEFAULT_FROM_EMAIL: str = f'Company Name <[email protected]>' $ mypy .
# Success: no issues found in [x] source files Of course, I can make the error go away by adding the type hint, but I'd prefer to not have to explicitly add types for all variables in my |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In recent versions, the mypy plugin of django-stubs has started issuing a new warning in cases where the plugin is unable to resolve the type of a setting, for example:
Causes error:
The recommended solution is to add an explicit type hint into the main settings file that is used by the django-stubs:
(thanks to @flaeppe in #1163 (comment))
Beta Was this translation helpful? Give feedback.
All reactions