Skip to content

Commit f166cea

Browse files
committed
test that type errors inside the default are caught
1 parent a7db969 commit f166cea

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test-data/unit/check-class-namedtuple.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ reveal_type(HasNone(1)) # E: Revealed type is 'Tuple[builtins.int, builtins.int
411411

412412
class Parameterized(NamedTuple):
413413
x: int
414-
y: List[int] = []
414+
y: List[int] = [1] + [2]
415415

416416
reveal_type(Parameterized(1)) # E: Revealed type is 'Tuple[builtins.int, builtins.list[builtins.int], fallback=__main__.Parameterized]'
417417
Parameterized(1, ['not an int']) # E: List item 0 has incompatible type "str"
@@ -435,6 +435,13 @@ class X(NamedTuple):
435435
x: int
436436
y: int = 'not an int' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
437437

438+
[case testNewNamedTupleErrorInDefault]
439+
# flags: --fast-parser --python-version 3.6
440+
from typing import NamedTuple
441+
442+
class X(NamedTuple):
443+
x: int = 1 + '1' # E: Unsupported operand types for + ("int" and "str")
444+
438445
[case testNewNamedTupleInheritance]
439446
# flags: --fast-parser --python-version 3.6
440447
from typing import cast, NamedTuple

0 commit comments

Comments
 (0)