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
33
44from django .apps .registry import Apps
55from django .db .models .base import Model
6- from django .utils .functional import _StrOrPromise , cached_property
6+ from django .utils .functional import _Getter , _StrOrPromise
77
88APPS_MODULE_NAME : str
99MODELS_MODULE_NAME : str
@@ -16,10 +16,11 @@ class AppConfig:
1616 verbose_name : _StrOrPromise
1717 path : str
1818 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
1921 models : dict [str , type [Model ]]
22+ default_auto_field : str | _Getter [str ]
2023 def __init__ (self , app_name : str , app_module : types .ModuleType | None ) -> None : ...
21- @cached_property
22- def default_auto_field (self ) -> str : ...
2324 @classmethod
2425 def create (cls , entry : str ) -> AppConfig : ...
2526 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