mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 14:01:56 +08:00
cleanups, fix settings
This commit is contained in:
52
test-data/typecheck/settings.test
Normal file
52
test-data/typecheck/settings.test
Normal file
@@ -0,0 +1,52 @@
|
||||
[CASE test_settings_are_parsed_into_django_conf_settings]
|
||||
from django.conf import settings
|
||||
|
||||
reveal_type(settings.ROOT_DIR) # E: Revealed type is 'builtins.str'
|
||||
reveal_type(settings.OBJ) # E: Revealed type is 'django.utils.functional.LazyObject'
|
||||
reveal_type(settings.NUMBERS) # E: Revealed type is 'builtins.list[builtins.str]'
|
||||
reveal_type(settings.DICT) # E: Revealed type is 'builtins.dict[Any, Any]'
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
SECRET_KEY = 112233
|
||||
ROOT_DIR = '/etc'
|
||||
NUMBERS = ['one', 'two']
|
||||
DICT = {} # type: ignore
|
||||
from django.utils.functional import LazyObject
|
||||
OBJ = LazyObject()
|
||||
|
||||
[CASE test_settings_could_be_defined_in_different_module_and_imported_with_star]
|
||||
from django.conf import settings
|
||||
|
||||
reveal_type(settings.ROOT_DIR) # E: Revealed type is 'pathlib.Path'
|
||||
reveal_type(settings.SETUP) # E: Revealed type is 'builtins.int'
|
||||
reveal_type(settings.DATABASES) # E: Revealed type is 'builtins.dict[builtins.str, builtins.str]'
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
from local import *
|
||||
DATABASES = {'default': 'mydb'}
|
||||
[file local.py]
|
||||
from base import *
|
||||
SETUP = 3
|
||||
[file base.py]
|
||||
from pathlib import Path
|
||||
|
||||
ROOT_DIR = Path(__file__)
|
||||
|
||||
[CASE test_circular_dependency_in_settings]
|
||||
from django.conf import settings
|
||||
class Class:
|
||||
pass
|
||||
reveal_type(settings.MYSETTING) # E: Revealed type is 'builtins.int'
|
||||
reveal_type(settings.REGISTRY) # E: Revealed type is 'Union[main.Class, None]'
|
||||
|
||||
[env DJANGO_SETTINGS_MODULE=mysettings]
|
||||
[file mysettings.py]
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Optional
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from main import Class
|
||||
|
||||
MYSETTING = 1122
|
||||
REGISTRY: Optional['Class'] = None
|
||||
|
||||
Reference in New Issue
Block a user