Skip to content

Commit 17aec67

Browse files
authored
Add test case for fixed dataclass-in-function crash (#12793)
Closes #8703, which is a crash that was fixed by #12762
1 parent e63501c commit 17aec67

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test-data/unit/check-dataclasses.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,20 @@ A(a=func).a()
15661566
A(a=func).a = func # E: Property "a" defined in "A" is read-only
15671567
[builtins fixtures/dataclasses.pyi]
15681568

1569+
[case testDataclassInFunctionDoesNotCrash]
1570+
# flags: --python-version 3.7
1571+
from dataclasses import dataclass
1572+
1573+
def foo():
1574+
@dataclass
1575+
class Foo:
1576+
foo: int
1577+
# This used to crash (see #8703)
1578+
# The return type of __call__ here needs to be something undefined
1579+
# In order to trigger the crash that existed prior to #12762
1580+
def __call__(self) -> asdf: ... # E: Name "asdf" is not defined
1581+
[builtins fixtures/dataclasses.pyi]
1582+
15691583
[case testDataclassesMultipleInheritanceWithNonDataclass]
15701584
# flags: --python-version 3.10
15711585
from dataclasses import dataclass

0 commit comments

Comments
 (0)