-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase priority of mypy internal Django settings import (#2127)
As discussed in #2097 (reply in thread): * django-stubs 5.0.0 introduces new cases of the "Import cycle from Django settings module prevents type inference" error that did not occur in 4.2.7. * This was bisected down to the change in commit e517a1f (#2024). * Updated the priority of internal settings import to mypy's `PRI_HIGH` level. Related commit a10f8aa (#2098)
- Loading branch information
Showing
2 changed files
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
- case: test_setting_circular_import | ||
main: | | ||
from myapp import lib | ||
custom_settings: | | ||
from myapp.lib import function_returning_int | ||
IMMEDIATE_VALUE = 123 | ||
CIRCULAR_WITHOUT_HINT = function_returning_int() | ||
CIRCULAR_WITH_HINT: int = function_returning_int() | ||
mypy_config: | | ||
[mypy.plugins.django-stubs] | ||
django_settings_module = myapp.settings | ||
files: | ||
- path: myapp/__init__.py | ||
- path: myapp/settings.py | ||
content: | | ||
from myapp.lib import function_returning_int, const_with_circular_import | ||
IMMEDIATE_VALUE = 123 | ||
CIRCULAR_WITH_HINT: int = function_returning_int() | ||
CIRCULAR_WITHOUT_HINT_FUNCTION = function_returning_int() | ||
CIRCULAR_WITHOUT_HINT_CONST = const_with_circular_import | ||
- path: myapp/lib.py | ||
content: | | ||
from django.conf import settings | ||
from typing import TYPE_CHECKING | ||
import django.conf | ||
settings = django.conf.settings | ||
def test() -> None: | ||
reveal_type(settings.IMMEDIATE_VALUE) # N: Revealed type is "builtins.int" | ||
reveal_type(settings.CIRCULAR_WITHOUT_HINT) # E: Import cycle from Django settings module prevents type inference for 'CIRCULAR_WITHOUT_HINT' [misc] # N: Revealed type is "Any" | ||
reveal_type(settings.CIRCULAR_WITH_HINT) # N: Revealed type is "builtins.int" | ||
reveal_type(settings.CIRCULAR_WITHOUT_HINT_FUNCTION) # E: Import cycle from Django settings module prevents type inference for 'CIRCULAR_WITHOUT_HINT_FUNCTION' [misc] # N: Revealed type is "Any" | ||
reveal_type(settings.CIRCULAR_WITHOUT_HINT_CONST) # E: Import cycle from Django settings module prevents type inference for 'CIRCULAR_WITHOUT_HINT_CONST' [misc] # N: Revealed type is "Any" | ||
def function_returning_int() -> int: | ||
return 42 | ||
if TYPE_CHECKING: | ||
const_with_circular_import = settings.IMMEDIATE_VALUE | ||
else: | ||
const_with_circular_import = 0 |