Skip to content

Commit fec994a

Browse files
authored
Migrate apps/test_config.yml 'assert_type' tests (#2190)
* Migrate `apps/test_config.yml` 'assert_type' tests * fixup! Migrate `apps/test_config.yml` 'assert_type' tests
1 parent a90cf3e commit fec994a

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.apps.config import AppConfig
2+
from django.utils.functional import cached_property
3+
from typing_extensions import assert_type
4+
5+
6+
class FooConfig(AppConfig):
7+
name = "foo"
8+
default_auto_field = "django.db.models.BigAutoField"
9+
10+
11+
class BarConfig(AppConfig):
12+
name = "foo"
13+
14+
@property
15+
def default_auto_field(self) -> str: # type: ignore[override]
16+
return "django.db.models.BigAutoField"
17+
18+
19+
class BazConfig(AppConfig):
20+
name = "foo"
21+
22+
@cached_property
23+
def default_auto_field(self) -> str: # type: ignore[override]
24+
return "django.db.models.BigAutoField"
25+
26+
27+
class FooBarConfig(AppConfig):
28+
name = "foo"
29+
default_auto_field = cached_property(lambda self: "django.db.models.BigAutoField")
30+
31+
32+
# Pyright correctly picks up our fake '_Getter' descriptor on class level. But we
33+
# silence the pyright error since mypy doesn't follow along and the fake descriptor
34+
# is a stubs detail made to round other problems.
35+
assert_type(FooConfig.default_auto_field, str) # pyright: ignore[reportAssertTypeFailure]
36+
assert_type(BarConfig("bar", None).default_auto_field, str)
37+
assert_type(BazConfig("baz", None).default_auto_field, str)
38+
assert_type(FooBarConfig("baz", None).default_auto_field, str)

tests/typecheck/apps/test_config.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)