mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 12:14:28 +08:00
99 lines
2.9 KiB
Plaintext
99 lines
2.9 KiB
Plaintext
[CASE test_settings_are_parsed_into_django_conf_settings]
|
|
[env DJANGO_SETTINGS_MODULE=mysettings]
|
|
[disable_cache]
|
|
from django.conf import settings
|
|
|
|
# standard settings
|
|
reveal_type(settings.AUTH_USER_MODEL) # N: Revealed type is 'builtins.str'
|
|
|
|
reveal_type(settings.ROOT_DIR) # N: Revealed type is 'builtins.str'
|
|
reveal_type(settings.APPS_DIR) # N: Revealed type is 'pathlib.Path'
|
|
reveal_type(settings.OBJ) # N: Revealed type is 'django.utils.functional.LazyObject'
|
|
reveal_type(settings.NUMBERS) # N: Revealed type is 'builtins.list[builtins.str*]'
|
|
reveal_type(settings.DICT) # N: Revealed type is 'builtins.dict[Any, Any]'
|
|
[file base.py]
|
|
from pathlib import Path
|
|
ROOT_DIR = '/etc'
|
|
APPS_DIR = Path(ROOT_DIR)
|
|
[file mysettings.py]
|
|
from base import *
|
|
SECRET_KEY = 112233
|
|
NUMBERS = ['one', 'two']
|
|
DICT = {} # type: ignore
|
|
from django.utils.functional import LazyObject
|
|
OBJ = LazyObject()
|
|
[/CASE]
|
|
|
|
[CASE test_settings_could_be_defined_in_different_module_and_imported_with_star]
|
|
[env DJANGO_SETTINGS_MODULE=mysettings]
|
|
[disable_cache]
|
|
from django.conf import settings
|
|
|
|
reveal_type(settings.ROOT_DIR) # N: Revealed type is 'pathlib.Path'
|
|
reveal_type(settings.SETUP) # N: Revealed type is 'Union[builtins.int, None]'
|
|
reveal_type(settings.DATABASES) # N: Revealed type is 'builtins.dict[builtins.str*, builtins.str*]'
|
|
|
|
reveal_type(settings.LOCAL_SETTING) # N: Revealed type is 'builtins.int'
|
|
reveal_type(settings.BASE_SETTING) # N: Revealed type is 'builtins.int'
|
|
|
|
[file mysettings.py]
|
|
from local import *
|
|
from typing import Optional
|
|
SETUP: Optional[int] = 3
|
|
|
|
[file local.py]
|
|
from base import *
|
|
SETUP: int = 3
|
|
DATABASES = {'default': 'mydb'}
|
|
|
|
LOCAL_SETTING = 1
|
|
|
|
[file base.py]
|
|
from pathlib import Path
|
|
from typing import Any
|
|
SETUP: Any = None
|
|
ROOT_DIR = Path(__file__)
|
|
|
|
BASE_SETTING = 1
|
|
|
|
[/CASE]
|
|
|
|
[CASE global_settings_are_always_loaded]
|
|
from django.conf import settings
|
|
|
|
reveal_type(settings.AUTH_USER_MODEL) # N: Revealed type is 'builtins.str'
|
|
reveal_type(settings.AUTHENTICATION_BACKENDS) # N: Revealed type is 'typing.Sequence[builtins.str]'
|
|
[/CASE]
|
|
|
|
[CASE test_circular_dependency_in_settings_works_if_settings_have_annotations]
|
|
[env DJANGO_SETTINGS_MODULE=mysettings]
|
|
[disable_cache]
|
|
from django.conf import settings
|
|
class Class:
|
|
pass
|
|
reveal_type(settings.MYSETTING) # N: Revealed type is 'builtins.int'
|
|
reveal_type(settings.REGISTRY) # N: Revealed type is 'Union[main.Class, None]'
|
|
reveal_type(settings.LIST) # N: Revealed type is 'builtins.list[builtins.str]'
|
|
|
|
[file mysettings.py]
|
|
from typing import TYPE_CHECKING, Optional, List
|
|
|
|
if TYPE_CHECKING:
|
|
from main import Class
|
|
|
|
MYSETTING = 1122
|
|
REGISTRY: Optional['Class'] = None
|
|
LIST: List[str] = ['1', '2']
|
|
[/CASE]
|
|
|
|
[CASE fail_if_there_is_no_setting]
|
|
from django.conf import settings
|
|
reveal_type(settings.NOT_EXISTING)
|
|
|
|
[env DJANGO_SETTINGS_MODULE=mysettings2]
|
|
[disable_cache]
|
|
[file mysettings2.py]
|
|
[out]
|
|
main:2: note: Revealed type is 'Any'
|
|
main:2: error: 'Settings' object has no attribute 'NOT_EXISTING'
|
|
[/CASE] |