File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ from collections.abc import Iterator
3
3
4
4
from django .apps .registry import Apps
5
5
from django .db .models .base import Model
6
- from django .utils .functional import _StrOrPromise , cached_property
6
+ from django .utils .functional import _Getter , _StrOrPromise
7
7
8
8
APPS_MODULE_NAME : str
9
9
MODELS_MODULE_NAME : str
@@ -16,10 +16,11 @@ class AppConfig:
16
16
verbose_name : _StrOrPromise
17
17
path : str
18
18
models_module : str | None
19
+ # Default auto_field is a cached_property on the base, but is usually subclassed as a str
20
+ # If not subclassing with a str, a type ignore[override] is needed
19
21
models : dict [str , type [Model ]]
22
+ default_auto_field : str | _Getter [str ]
20
23
def __init__ (self , app_name : str , app_module : types .ModuleType | None ) -> None : ...
21
- @cached_property
22
- def default_auto_field (self ) -> str : ...
23
24
@classmethod
24
25
def create (cls , entry : str ) -> AppConfig : ...
25
26
def get_model (self , model_name : str , require_ready : bool = ...) -> type [Model ]: ...
Original file line number Diff line number Diff line change
1
+ - case : test_appconfig_can_be_str
2
+ main : |
3
+ from django.apps.config import AppConfig
4
+ from django.utils.functional import cached_property
5
+
6
+ class FooConfig(AppConfig):
7
+ name = "foo"
8
+ default_auto_field = "django.db.models.BigAutoField"
9
+
10
+ class BarConfig(AppConfig):
11
+ name = "foo"
12
+ @property
13
+ def default_auto_field(self) -> str: # type: ignore[override]
14
+ return "django.db.models.BigAutoField"
15
+
16
+ class BazConfig(AppConfig):
17
+ name = "foo"
18
+ @cached_property
19
+ def default_auto_field(self) -> str: # type: ignore[override]
20
+ return "django.db.models.BigAutoField"
21
+
22
+ class FooBarConfig(AppConfig):
23
+ name = "foo"
24
+ default_auto_field = cached_property(lambda self: "django.db.models.BigAutoField")
25
+
26
+ reveal_type(FooConfig.default_auto_field) # N: Revealed type is "builtins.str"
27
+ reveal_type(BarConfig("bar", None).default_auto_field) # N: Revealed type is "builtins.str"
28
+ reveal_type(BazConfig("baz", None).default_auto_field) # N: Revealed type is "builtins.str"
29
+ reveal_type(FooBarConfig("baz", None).default_auto_field) # N: Revealed type is "builtins.str"
You can’t perform that action at this time.
0 commit comments