From b203117c9b9e8ef3159feb979a2d809e1842ec51 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Sun, 9 Aug 2026 16:14:32 -0400 Subject: [PATCH] add tests for ClassVar/Final in NamedTuple and TypedDict --- .../results/mypy/classes_classvar.toml | 46 ++++++++++--------- .../mypy/qualifiers_final_annotation.toml | 34 +++++++------- .../results/pycroscope/classes_classvar.toml | 40 +++++++++------- .../qualifiers_final_annotation.toml | 24 +++++----- .../results/pyrefly/classes_classvar.toml | 44 +++++++++--------- .../pyrefly/qualifiers_final_annotation.toml | 28 +++++------ .../results/pyright/classes_classvar.toml | 34 +++++++------- .../pyright/qualifiers_final_annotation.toml | 28 ++++++----- conformance/results/results.html | 11 +++-- conformance/results/ty/classes_classvar.toml | 34 +++++++------- .../ty/qualifiers_final_annotation.toml | 26 ++++++----- .../results/zuban/classes_classvar.toml | 40 ++++++++-------- .../zuban/qualifiers_final_annotation.toml | 26 ++++++----- conformance/tests/classes_classvar.py | 16 +++++++ .../tests/qualifiers_final_annotation.py | 16 ++++++- 15 files changed, 256 insertions(+), 191 deletions(-) diff --git a/conformance/results/mypy/classes_classvar.toml b/conformance/results/mypy/classes_classvar.toml index 853c49684..238b36032 100644 --- a/conformance/results/mypy/classes_classvar.toml +++ b/conformance/results/mypy/classes_classvar.toml @@ -6,32 +6,34 @@ Rejects `ClassVar` nested in `Annotated`. Does not reject use of `ClassVar` in `TypeAlias` definition. """ output = """ -classes_classvar.py:38: error: ClassVar[...] must have at most one type argument [valid-type] -classes_classvar.py:39: error: Invalid type: try using Literal[3] instead? [valid-type] -classes_classvar.py:40: error: Name "var" is not defined; did you mean "var1" or "vars"? [name-defined] -classes_classvar.py:52: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment] -classes_classvar.py:54: error: Variable should not be annotated with both ClassVar and Final [misc] -classes_classvar.py:55: error: Invalid type: ClassVar nested inside other type [valid-type] -classes_classvar.py:67: error: Invalid type: ClassVar nested inside other type [valid-type] -classes_classvar.py:69: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:70: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:40: error: ClassVar[...] must have at most one type argument [valid-type] +classes_classvar.py:41: error: Invalid type: try using Literal[3] instead? [valid-type] +classes_classvar.py:42: error: Name "var" is not defined; did you mean "var1" or "vars"? [name-defined] +classes_classvar.py:54: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment] +classes_classvar.py:56: error: Variable should not be annotated with both ClassVar and Final [misc] +classes_classvar.py:57: error: Invalid type: ClassVar nested inside other type [valid-type] +classes_classvar.py:69: error: Invalid type: ClassVar nested inside other type [valid-type] classes_classvar.py:71: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:72: error: ClassVar can only be used for assignments in class body [misc] classes_classvar.py:73: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:77: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:78: error: ClassVar[...] can't be used inside a type alias [valid-type] -classes_classvar.py:111: error: Cannot assign to class variable "stats" via instance [misc] -classes_classvar.py:130: error: All protocol members must have explicitly declared types [misc] -classes_classvar.py:140: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment] -classes_classvar.py:140: note: "ProtoAImpl" is missing following "ProtoA" protocol member: -classes_classvar.py:140: note: z -classes_classvar.py:140: note: Protocol member ProtoA.x expected class variable, got instance variable -classes_classvar.py:140: note: Protocol member ProtoA.y expected class variable, got instance variable +classes_classvar.py:75: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:79: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:80: error: ClassVar[...] can't be used inside a type alias [valid-type] +classes_classvar.py:89: error: ClassVar[...] can't be used inside a TypedDict [valid-type] +classes_classvar.py:94: error: ClassVar[...] can't be used inside a NamedTuple [valid-type] +classes_classvar.py:127: error: Cannot assign to class variable "stats" via instance [misc] +classes_classvar.py:146: error: All protocol members must have explicitly declared types [misc] +classes_classvar.py:156: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment] +classes_classvar.py:156: note: "ProtoAImpl" is missing following "ProtoA" protocol member: +classes_classvar.py:156: note: z +classes_classvar.py:156: note: Protocol member ProtoA.x expected class variable, got instance variable +classes_classvar.py:156: note: Protocol member ProtoA.y expected class variable, got instance variable """ conformance_automated = "Fail" errors_diff = """ -Line 45: Expected 1 errors -Line 46: Expected 1 errors Line 47: Expected 1 errors -Line 67: Unexpected errors ['classes_classvar.py:67: error: Invalid type: ClassVar nested inside other type [valid-type]'] -Line 130: Unexpected errors ['classes_classvar.py:130: error: All protocol members must have explicitly declared types [misc]'] +Line 48: Expected 1 errors +Line 49: Expected 1 errors +Line 69: Unexpected errors ['classes_classvar.py:69: error: Invalid type: ClassVar nested inside other type [valid-type]'] +Line 146: Unexpected errors ['classes_classvar.py:146: error: All protocol members must have explicitly declared types [misc]'] """ diff --git a/conformance/results/mypy/qualifiers_final_annotation.toml b/conformance/results/mypy/qualifiers_final_annotation.toml index 137e9f808..099d55b0c 100644 --- a/conformance/results/mypy/qualifiers_final_annotation.toml +++ b/conformance/results/mypy/qualifiers_final_annotation.toml @@ -24,25 +24,27 @@ qualifiers_final_annotation.py:107: error: Final can be only used as an outermos qualifiers_final_annotation.py:108: error: Variable should not be annotated with both ClassVar and Final [misc] qualifiers_final_annotation.py:118: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type] qualifiers_final_annotation.py:121: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type] -qualifiers_final_annotation.py:131: error: Invalid "NamedTuple()" field name [misc] -qualifiers_final_annotation.py:133: error: Unexpected keyword argument "x" for "N" [call-arg] -qualifiers_final_annotation.py:133: error: Unexpected keyword argument "y" for "N" [call-arg] -qualifiers_final_annotation.py:134: error: Unexpected keyword argument "a" for "N" [call-arg] -qualifiers_final_annotation.py:135: error: Unexpected keyword argument "x" for "N" [call-arg] -qualifiers_final_annotation.py:135: error: Unexpected keyword argument "y" for "N" [call-arg] -qualifiers_final_annotation.py:141: error: Cannot assign to final name "ID1" [misc] -qualifiers_final_annotation.py:145: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:147: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:152: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "int") [assignment] -qualifiers_final_annotation.py:155: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:166: error: Cannot assign to final name "TEN" [misc] -qualifiers_final_annotation.py:170: error: Cannot assign to final name "PI" [misc] +qualifiers_final_annotation.py:131: error: Final[...] can't be used inside a TypedDict [valid-type] +qualifiers_final_annotation.py:136: error: Final[...] can't be used inside a NamedTuple [valid-type] +qualifiers_final_annotation.py:145: error: Invalid "NamedTuple()" field name [misc] +qualifiers_final_annotation.py:147: error: Unexpected keyword argument "x" for "N" [call-arg] +qualifiers_final_annotation.py:147: error: Unexpected keyword argument "y" for "N" [call-arg] +qualifiers_final_annotation.py:148: error: Unexpected keyword argument "a" for "N" [call-arg] +qualifiers_final_annotation.py:149: error: Unexpected keyword argument "x" for "N" [call-arg] +qualifiers_final_annotation.py:149: error: Unexpected keyword argument "y" for "N" [call-arg] +qualifiers_final_annotation.py:155: error: Cannot assign to final name "ID1" [misc] +qualifiers_final_annotation.py:159: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:161: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:166: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "int") [assignment] +qualifiers_final_annotation.py:169: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:180: error: Cannot assign to final name "TEN" [misc] +qualifiers_final_annotation.py:184: error: Cannot assign to final name "PI" [misc] """ conformance_automated = "Fail" errors_diff = """ -Line 149: Expected 1 errors +Line 163: Expected 1 errors Line 59: Unexpected errors ['qualifiers_final_annotation.py:59: error: Cannot assign to final attribute "ID6" [misc]'] Line 96: Unexpected errors ['qualifiers_final_annotation.py:96: error: Cannot assign to final name "__private" [misc]'] -Line 131: Unexpected errors ['qualifiers_final_annotation.py:131: error: Invalid "NamedTuple()" field name [misc]'] -Line 133: Unexpected errors ['qualifiers_final_annotation.py:133: error: Unexpected keyword argument "x" for "N" [call-arg]', 'qualifiers_final_annotation.py:133: error: Unexpected keyword argument "y" for "N" [call-arg]'] +Line 145: Unexpected errors ['qualifiers_final_annotation.py:145: error: Invalid "NamedTuple()" field name [misc]'] +Line 147: Unexpected errors ['qualifiers_final_annotation.py:147: error: Unexpected keyword argument "x" for "N" [call-arg]', 'qualifiers_final_annotation.py:147: error: Unexpected keyword argument "y" for "N" [call-arg]'] """ diff --git a/conformance/results/pycroscope/classes_classvar.toml b/conformance/results/pycroscope/classes_classvar.toml index a377b105f..23479ff47 100644 --- a/conformance/results/pycroscope/classes_classvar.toml +++ b/conformance/results/pycroscope/classes_classvar.toml @@ -1,22 +1,28 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = """ +Does not reject use of `ClassVar` as a qualifier for a NamedTuple field. +""" +conformance_automated = "Fail" errors_diff = """ +Line 94: Expected 1 errors """ output = """ -./classes_classvar.py:38:10: Invalid type annotation (, ) [invalid_annotation] -./classes_classvar.py:39:10: Invalid type annotation 3 [invalid_annotation] -./classes_classvar.py:40:13: Undefined name: var [undefined_name] -./classes_classvar.py:45:10: ClassVar type cannot include type parameters [classvar_type_parameters] -./classes_classvar.py:46:10: ClassVar type cannot include type parameters [classvar_type_parameters] +./classes_classvar.py:40:10: Invalid type annotation (, ) [invalid_annotation] +./classes_classvar.py:41:10: Invalid type annotation 3 [invalid_annotation] +./classes_classvar.py:42:13: Undefined name: var [undefined_name] ./classes_classvar.py:47:10: ClassVar type cannot include type parameters [classvar_type_parameters] -./classes_classvar.py:52:4: Incompatible assignment: expected list[str], got Literal[{}] [incompatible_assignment] -./classes_classvar.py:54:10: Final cannot be combined with ClassVar [invalid_qualifier] -./classes_classvar.py:55:11: Unrecognized annotation typing.ClassVar[] [invalid_annotation] -./classes_classvar.py:69:25: Unexpected ClassVar annotation [invalid_qualifier] -./classes_classvar.py:70:11: ClassVar can only be used for assignments in class body [invalid_qualifier] -./classes_classvar.py:71:17: ClassVar can only be used for assignments in class body [invalid_qualifier] -./classes_classvar.py:73:25: Unexpected ClassVar annotation [invalid_qualifier] -./classes_classvar.py:77:7: ClassVar can only be used for assignments in class body [invalid_qualifier] -./classes_classvar.py:78:19: ClassVar cannot be used in type aliases [invalid_qualifier] -./classes_classvar.py:111:0: Cannot assign to class variable 'stats' via instance [incompatible_assignment] -./classes_classvar.py:140:0: Incompatible assignment: expected ./classes_classvar.py.ProtoA, got ./classes_classvar.py.ProtoAImpl [incompatible_assignment] +./classes_classvar.py:48:10: ClassVar type cannot include type parameters [classvar_type_parameters] +./classes_classvar.py:49:10: ClassVar type cannot include type parameters [classvar_type_parameters] +./classes_classvar.py:54:4: Incompatible assignment: expected list[str], got Literal[{}] [incompatible_assignment] +./classes_classvar.py:56:10: Final cannot be combined with ClassVar [invalid_qualifier] +./classes_classvar.py:57:11: Unrecognized annotation typing.ClassVar[] [invalid_annotation] +./classes_classvar.py:71:25: Unexpected ClassVar annotation [invalid_qualifier] +./classes_classvar.py:72:11: ClassVar can only be used for assignments in class body [invalid_qualifier] +./classes_classvar.py:73:17: ClassVar can only be used for assignments in class body [invalid_qualifier] +./classes_classvar.py:75:25: Unexpected ClassVar annotation [invalid_qualifier] +./classes_classvar.py:79:7: ClassVar can only be used for assignments in class body [invalid_qualifier] +./classes_classvar.py:80:19: ClassVar cannot be used in type aliases [invalid_qualifier] +./classes_classvar.py:89:7: Unexpected ClassVar annotation [invalid_qualifier] +./classes_classvar.py:127:0: Cannot assign to class variable 'stats' via instance [incompatible_assignment] +./classes_classvar.py:156:0: Incompatible assignment: expected ./classes_classvar.py.ProtoA, got ./classes_classvar.py.ProtoAImpl [incompatible_assignment] """ diff --git a/conformance/results/pycroscope/qualifiers_final_annotation.toml b/conformance/results/pycroscope/qualifiers_final_annotation.toml index 07fc0d812..0784a273e 100644 --- a/conformance/results/pycroscope/qualifiers_final_annotation.toml +++ b/conformance/results/pycroscope/qualifiers_final_annotation.toml @@ -19,15 +19,17 @@ output = """ ./qualifiers_final_annotation.py:108:12: Final cannot be combined with ClassVar [invalid_qualifier] ./qualifiers_final_annotation.py:118:3: Unrecognized annotation typing.Final[] [invalid_annotation] ./qualifiers_final_annotation.py:121:13: Unexpected Final annotation [invalid_qualifier] -./qualifiers_final_annotation.py:134:0: In call to pycroscope.signature.N: Missing required argument 'x' [incompatible_call] -./qualifiers_final_annotation.py:135:4: Incompatible argument type for x: expected int but got Literal[''] [incompatible_argument] -./qualifiers_final_annotation.py:135:10: Incompatible argument type for y: expected int but got Literal[''] [incompatible_argument] -./qualifiers_final_annotation.py:141:4: Cannot assign to final name ID1 [incompatible_assignment] -./qualifiers_final_annotation.py:145:4: Cannot assign to final name x [incompatible_assignment] -./qualifiers_final_annotation.py:147:9: Cannot assign to final name x [incompatible_assignment] -./qualifiers_final_annotation.py:149:8: Cannot assign to final name x [incompatible_assignment] -./qualifiers_final_annotation.py:152:29: Cannot assign to final name x [incompatible_assignment] -./qualifiers_final_annotation.py:155:8: Cannot assign to final name x [incompatible_assignment] -./qualifiers_final_annotation.py:166:0: Cannot assign to final name TEN [incompatible_assignment] -./qualifiers_final_annotation.py:170:0: Cannot assign to final name PI [incompatible_assignment] +./qualifiers_final_annotation.py:131:7: Unexpected Final annotation [invalid_qualifier] +./qualifiers_final_annotation.py:136:4: Final class attributes without initializers must be assigned in __init__ [invalid_qualifier] +./qualifiers_final_annotation.py:148:0: In call to pycroscope.signature.N: Missing required argument 'x' [incompatible_call] +./qualifiers_final_annotation.py:149:4: Incompatible argument type for x: expected int but got Literal[''] [incompatible_argument] +./qualifiers_final_annotation.py:149:10: Incompatible argument type for y: expected int but got Literal[''] [incompatible_argument] +./qualifiers_final_annotation.py:155:4: Cannot assign to final name ID1 [incompatible_assignment] +./qualifiers_final_annotation.py:159:4: Cannot assign to final name x [incompatible_assignment] +./qualifiers_final_annotation.py:161:9: Cannot assign to final name x [incompatible_assignment] +./qualifiers_final_annotation.py:163:8: Cannot assign to final name x [incompatible_assignment] +./qualifiers_final_annotation.py:166:29: Cannot assign to final name x [incompatible_assignment] +./qualifiers_final_annotation.py:169:8: Cannot assign to final name x [incompatible_assignment] +./qualifiers_final_annotation.py:180:0: Cannot assign to final name TEN [incompatible_assignment] +./qualifiers_final_annotation.py:184:0: Cannot assign to final name PI [incompatible_assignment] """ diff --git a/conformance/results/pyrefly/classes_classvar.toml b/conformance/results/pyrefly/classes_classvar.toml index 551f730b1..92c5a5257 100644 --- a/conformance/results/pyrefly/classes_classvar.toml +++ b/conformance/results/pyrefly/classes_classvar.toml @@ -3,25 +3,27 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ -ERROR classes_classvar.py:38:11-29: Expected 1 type argument for `ClassVar`, got 2 [invalid-annotation] -ERROR classes_classvar.py:39:14-15: Number literal cannot be used in annotations [invalid-annotation] -ERROR classes_classvar.py:40:14-17: Could not find name `var` [unknown-name] -ERROR classes_classvar.py:45:20-21: `ClassVar` arguments may not contain any type variables [invalid-annotation] -ERROR classes_classvar.py:46:20-27: `ClassVar` arguments may not contain any type variables [invalid-annotation] -ERROR classes_classvar.py:47:20-36: `ClassVar` arguments may not contain any type variables [invalid-annotation] -ERROR classes_classvar.py:52:33-35: `dict[@_, @_]` is not assignable to `list[str]` [bad-assignment] -ERROR classes_classvar.py:54:17-30: `ClassVar` may not be nested inside `Final` [invalid-annotation] -ERROR classes_classvar.py:55:17-30: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:69:26-34: `ClassVar` is only allowed inside a class body [invalid-annotation] -ERROR classes_classvar.py:69:26-39: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:70:12-20: `ClassVar` is only allowed inside a class body [invalid-annotation] -ERROR classes_classvar.py:70:12-25: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:71:9-16: Cannot set field `xx` [read-only] -ERROR classes_classvar.py:73:26-34: `ClassVar` is only allowed inside a class body [invalid-annotation] -ERROR classes_classvar.py:73:26-39: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:77:8-16: `ClassVar` is only allowed inside a class body [invalid-annotation] -ERROR classes_classvar.py:77:8-21: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:78:20-33: `ClassVar` is not allowed in this context [invalid-annotation] -ERROR classes_classvar.py:111:1-19: Cannot set field `stats` [read-only] -ERROR classes_classvar.py:140:13-25: `ProtoAImpl` is not assignable to `ProtoA` [bad-assignment] +ERROR classes_classvar.py:40:11-29: Expected 1 type argument for `ClassVar`, got 2 [invalid-annotation] +ERROR classes_classvar.py:41:14-15: Number literal cannot be used in annotations [invalid-annotation] +ERROR classes_classvar.py:42:14-17: Could not find name `var` [unknown-name] +ERROR classes_classvar.py:47:20-21: `ClassVar` arguments may not contain any type variables [invalid-annotation] +ERROR classes_classvar.py:48:20-27: `ClassVar` arguments may not contain any type variables [invalid-annotation] +ERROR classes_classvar.py:49:20-36: `ClassVar` arguments may not contain any type variables [invalid-annotation] +ERROR classes_classvar.py:54:33-35: `dict[@_, @_]` is not assignable to `list[str]` [bad-assignment] +ERROR classes_classvar.py:56:17-30: `ClassVar` may not be nested inside `Final` [invalid-annotation] +ERROR classes_classvar.py:57:17-30: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:71:26-34: `ClassVar` is only allowed inside a class body [invalid-annotation] +ERROR classes_classvar.py:71:26-39: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:72:12-20: `ClassVar` is only allowed inside a class body [invalid-annotation] +ERROR classes_classvar.py:72:12-25: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:73:9-16: Cannot set field `xx` [read-only] +ERROR classes_classvar.py:75:26-34: `ClassVar` is only allowed inside a class body [invalid-annotation] +ERROR classes_classvar.py:75:26-39: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:79:8-16: `ClassVar` is only allowed inside a class body [invalid-annotation] +ERROR classes_classvar.py:79:8-21: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:80:20-33: `ClassVar` is not allowed in this context [invalid-annotation] +ERROR classes_classvar.py:89:5-6: `ClassVar` may not be used for TypedDict members [invalid-annotation] +ERROR classes_classvar.py:94:5-6: `ClassVar` may not be used for NamedTuple members [invalid-annotation] +ERROR classes_classvar.py:127:1-19: Cannot set field `stats` [read-only] +ERROR classes_classvar.py:156:13-25: `ProtoAImpl` is not assignable to `ProtoA` [bad-assignment] """ diff --git a/conformance/results/pyrefly/qualifiers_final_annotation.toml b/conformance/results/pyrefly/qualifiers_final_annotation.toml index eda91ff00..4da0650c7 100644 --- a/conformance/results/pyrefly/qualifiers_final_annotation.toml +++ b/conformance/results/pyrefly/qualifiers_final_annotation.toml @@ -19,17 +19,19 @@ ERROR qualifiers_final_annotation.py:108:19-27: `ClassVar` may not be nested ins ERROR qualifiers_final_annotation.py:118:9-19: `Final` is not allowed in this context [invalid-annotation] ERROR qualifiers_final_annotation.py:121:14-19: `Final` is only allowed on a class or local variable annotation [invalid-annotation] ERROR qualifiers_final_annotation.py:121:14-30: `Final` is not allowed in this context [invalid-annotation] -ERROR qualifiers_final_annotation.py:134:2-7: Missing argument `x` in function `N.__new__` [missing-argument] -ERROR qualifiers_final_annotation.py:134:2-7: Missing argument `y` in function `N.__new__` [missing-argument] -ERROR qualifiers_final_annotation.py:134:3-4: Unexpected keyword argument `a` in function `N.__new__` [unexpected-keyword] -ERROR qualifiers_final_annotation.py:135:5-7: Argument `Literal['']` is not assignable to parameter `x` with type `int` in function `N.__new__` [bad-argument-type] -ERROR qualifiers_final_annotation.py:135:11-13: Argument `Literal['']` is not assignable to parameter `y` with type `int` in function `N.__new__` [bad-argument-type] -ERROR qualifiers_final_annotation.py:141:11-12: Cannot assign to variable `ID1` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:145:5-11: Cannot assign to variable `x` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:147:15-16: Cannot assign to variable `x` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:149:14-23: Cannot assign to variable `x` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:152:10-26: Cannot assign to variable `x` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:155:5-11: Cannot assign to variable `x` because it is marked final [bad-assignment] -ERROR qualifiers_final_annotation.py:166:1-4: Cannot assign to `TEN` because it is imported as final [bad-assignment] -ERROR qualifiers_final_annotation.py:170:1-3: Cannot assign to `PI` because it is imported as final [bad-assignment] +ERROR qualifiers_final_annotation.py:131:5-6: `Final` may not be used for TypedDict members [invalid-annotation] +ERROR qualifiers_final_annotation.py:136:5-6: `Final` may not be used for NamedTuple members [invalid-annotation] +ERROR qualifiers_final_annotation.py:148:2-7: Missing argument `x` in function `N.__new__` [missing-argument] +ERROR qualifiers_final_annotation.py:148:2-7: Missing argument `y` in function `N.__new__` [missing-argument] +ERROR qualifiers_final_annotation.py:148:3-4: Unexpected keyword argument `a` in function `N.__new__` [unexpected-keyword] +ERROR qualifiers_final_annotation.py:149:5-7: Argument `Literal['']` is not assignable to parameter `x` with type `int` in function `N.__new__` [bad-argument-type] +ERROR qualifiers_final_annotation.py:149:11-13: Argument `Literal['']` is not assignable to parameter `y` with type `int` in function `N.__new__` [bad-argument-type] +ERROR qualifiers_final_annotation.py:155:11-12: Cannot assign to variable `ID1` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:159:5-11: Cannot assign to variable `x` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:161:15-16: Cannot assign to variable `x` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:163:14-23: Cannot assign to variable `x` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:166:10-26: Cannot assign to variable `x` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:169:5-11: Cannot assign to variable `x` because it is marked final [bad-assignment] +ERROR qualifiers_final_annotation.py:180:1-4: Cannot assign to `TEN` because it is imported as final [bad-assignment] +ERROR qualifiers_final_annotation.py:184:1-3: Cannot assign to `PI` because it is imported as final [bad-assignment] """ diff --git a/conformance/results/pyright/classes_classvar.toml b/conformance/results/pyright/classes_classvar.toml index 1b03b11a3..19026e6f9 100644 --- a/conformance/results/pyright/classes_classvar.toml +++ b/conformance/results/pyright/classes_classvar.toml @@ -1,23 +1,25 @@ conformant = "Pass" output = """ -classes_classvar.py:38:25 - error: Expected only one type argument after "ClassVar" (reportInvalidTypeForm) -classes_classvar.py:39:14 - error: Expected class but received "Literal[3]" (reportGeneralTypeIssues) -classes_classvar.py:40:14 - error: "var" is not defined (reportUndefinedVariable) -classes_classvar.py:45:20 - error: "ClassVar" type cannot include type variables (reportGeneralTypeIssues) -classes_classvar.py:46:20 - error: "ClassVar" type cannot include type variables (reportGeneralTypeIssues) +classes_classvar.py:40:25 - error: Expected only one type argument after "ClassVar" (reportInvalidTypeForm) +classes_classvar.py:41:14 - error: Expected class but received "Literal[3]" (reportGeneralTypeIssues) +classes_classvar.py:42:14 - error: "var" is not defined (reportUndefinedVariable) classes_classvar.py:47:20 - error: "ClassVar" type cannot include type variables (reportGeneralTypeIssues) -classes_classvar.py:52:33 - error: Type "dict[Any, Any]" is not assignable to declared type "list[str]" (reportAssignmentType) -classes_classvar.py:54:17 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:55:17 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:69:26 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:70:12 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:71:18 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:73:26 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:77:8 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:78:20 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) -classes_classvar.py:111:14 - error: Cannot assign to attribute "stats" for class "Starship" +classes_classvar.py:48:20 - error: "ClassVar" type cannot include type variables (reportGeneralTypeIssues) +classes_classvar.py:49:20 - error: "ClassVar" type cannot include type variables (reportGeneralTypeIssues) +classes_classvar.py:54:33 - error: Type "dict[Any, Any]" is not assignable to declared type "list[str]" (reportAssignmentType) +classes_classvar.py:56:17 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:57:17 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:71:26 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:72:12 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:73:18 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:75:26 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:79:8 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:80:20 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:89:8 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:94:8 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) +classes_classvar.py:127:14 - error: Cannot assign to attribute "stats" for class "Starship"   Attribute "stats" cannot be assigned through a class instance because it is a ClassVar (reportAttributeAccessIssue) -classes_classvar.py:140:13 - error: Type "ProtoAImpl" is not assignable to declared type "ProtoA" +classes_classvar.py:156:13 - error: Type "ProtoAImpl" is not assignable to declared type "ProtoA"   "ProtoAImpl" is incompatible with protocol "ProtoA"     "x" is defined as a ClassVar in protocol     "y" is defined as a ClassVar in protocol (reportAssignmentType) diff --git a/conformance/results/pyright/qualifiers_final_annotation.toml b/conformance/results/pyright/qualifiers_final_annotation.toml index 38f55274a..0fb73bda6 100644 --- a/conformance/results/pyright/qualifiers_final_annotation.toml +++ b/conformance/results/pyright/qualifiers_final_annotation.toml @@ -25,20 +25,24 @@ qualifiers_final_annotation.py:107:22 - error: "Final" is not allowed in this co qualifiers_final_annotation.py:108:19 - error: "ClassVar" is not allowed in this context (reportInvalidTypeForm) qualifiers_final_annotation.py:118:9 - error: "Final" is not allowed in this context (reportInvalidTypeForm) qualifiers_final_annotation.py:121:14 - error: "Final" is not allowed in this context (reportInvalidTypeForm) -qualifiers_final_annotation.py:134:1 - error: Arguments missing for parameters "x", "y" (reportCallIssue) -qualifiers_final_annotation.py:134:3 - error: No parameter named "a" (reportCallIssue) -qualifiers_final_annotation.py:135:5 - error: Argument of type "Literal['']" cannot be assigned to parameter "x" of type "int" in function "__new__" +qualifiers_final_annotation.py:131:5 - error: "b" is declared Final, but value is not assigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:131:8 - error: "Final" is not allowed in this context (reportInvalidTypeForm) +qualifiers_final_annotation.py:136:5 - error: "b" is declared Final, but value is not assigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:136:8 - error: "Final" is not allowed in this context (reportInvalidTypeForm) +qualifiers_final_annotation.py:148:1 - error: Arguments missing for parameters "x", "y" (reportCallIssue) +qualifiers_final_annotation.py:148:3 - error: No parameter named "a" (reportCallIssue) +qualifiers_final_annotation.py:149:5 - error: Argument of type "Literal['']" cannot be assigned to parameter "x" of type "int" in function "__new__"   "Literal['']" is not assignable to "int" (reportArgumentType) -qualifiers_final_annotation.py:135:11 - error: Argument of type "Literal['']" cannot be assigned to parameter "y" of type "int" in function "__new__" +qualifiers_final_annotation.py:149:11 - error: Argument of type "Literal['']" cannot be assigned to parameter "y" of type "int" in function "__new__"   "Literal['']" is not assignable to "int" (reportArgumentType) -qualifiers_final_annotation.py:141:5 - error: "ID1" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:145:5 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:147:10 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:149:9 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:152:30 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:155:9 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:166:1 - error: "TEN" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) -qualifiers_final_annotation.py:170:1 - error: "PI" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:155:5 - error: "ID1" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:159:5 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:161:10 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:163:9 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:166:30 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:169:9 - error: "x" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:180:1 - error: "TEN" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) +qualifiers_final_annotation.py:184:1 - error: "PI" is declared as Final and cannot be reassigned (reportGeneralTypeIssues) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/results.html b/conformance/results/results.html index b342504bf..4de25dec5 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1038,7 +1038,12 @@

Python Type System Conformance Test Results

  • Does not reject use of ClassVar in TypeAlias definition.
  • - Pass + + Partial +
      +
    • Does not reject use of ClassVar as a qualifier for a NamedTuple field.
    • +
    + Pass Pass Pass @@ -1086,7 +1091,7 @@

    Python Type System Conformance Test Results

    1 / 2 • 50.0% - 1.5 / 2 • 75.0% + 1 / 2 • 50.0% 2 / 2 • 100.0% 1.5 / 2 • 75.0% 1.5 / 2 • 75.0% @@ -2647,7 +2652,7 @@

    Python Type System Conformance Test Results

    108 / 142 • 76.1% - 130.5 / 142 • 91.9% + 130 / 142 • 91.5% 141 / 142 • 99.3% 136 / 142 • 95.8% 125.5 / 142 • 88.4% diff --git a/conformance/results/ty/classes_classvar.toml b/conformance/results/ty/classes_classvar.toml index 1cadf9978..ff909e64b 100644 --- a/conformance/results/ty/classes_classvar.toml +++ b/conformance/results/ty/classes_classvar.toml @@ -2,21 +2,23 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ -classes_classvar.py:38:11: error[invalid-type-form] Type qualifier `typing.ClassVar` expected exactly 1 argument, got 2 -classes_classvar.py:39:14: error[invalid-type-form] Int literals are not allowed in this context in a type expression: Did you mean `typing.Literal[3]`? -classes_classvar.py:40:14: error[unresolved-reference] Name `var` used when not defined -classes_classvar.py:45:11: error[invalid-type-form] `ClassVar` cannot contain type variables -classes_classvar.py:46:11: error[invalid-type-form] `ClassVar` cannot contain type variables +classes_classvar.py:40:11: error[invalid-type-form] Type qualifier `typing.ClassVar` expected exactly 1 argument, got 2 +classes_classvar.py:41:14: error[invalid-type-form] Int literals are not allowed in this context in a type expression: Did you mean `typing.Literal[3]`? +classes_classvar.py:42:14: error[unresolved-reference] Name `var` used when not defined classes_classvar.py:47:11: error[invalid-type-form] `ClassVar` cannot contain type variables -classes_classvar.py:52:33: error[invalid-assignment] Object of type `dict[Unknown, Unknown]` is not assignable to `list[str]` -classes_classvar.py:54:11: error[redundant-final-classvar] `Combining `ClassVar` and `Final` is redundant -classes_classvar.py:55:17: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions) -classes_classvar.py:69:26: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in parameter annotations -classes_classvar.py:70:12: error[invalid-type-form] `ClassVar` is only allowed in class bodies -classes_classvar.py:71:18: error[invalid-type-form] `ClassVar` annotations are not allowed for non-name targets -classes_classvar.py:73:26: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in return type annotations -classes_classvar.py:77:8: error[invalid-type-form] `ClassVar` is only allowed in class bodies -classes_classvar.py:78:20: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in type alias values -classes_classvar.py:111:1: error[invalid-attribute-access] Cannot assign to ClassVar `stats` from an instance of type `Starship` -classes_classvar.py:140:13: error[invalid-assignment] Object of type `ProtoAImpl` is not assignable to `ProtoA` +classes_classvar.py:48:11: error[invalid-type-form] `ClassVar` cannot contain type variables +classes_classvar.py:49:11: error[invalid-type-form] `ClassVar` cannot contain type variables +classes_classvar.py:54:33: error[invalid-assignment] Object of type `dict[Unknown, Unknown]` is not assignable to `list[str]` +classes_classvar.py:56:11: error[redundant-final-classvar] `Combining `ClassVar` and `Final` is redundant +classes_classvar.py:57:17: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions) +classes_classvar.py:71:26: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in parameter annotations +classes_classvar.py:72:12: error[invalid-type-form] `ClassVar` is only allowed in class bodies +classes_classvar.py:73:18: error[invalid-type-form] `ClassVar` annotations are not allowed for non-name targets +classes_classvar.py:75:26: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in return type annotations +classes_classvar.py:79:8: error[invalid-type-form] `ClassVar` is only allowed in class bodies +classes_classvar.py:80:20: error[invalid-type-form] Type qualifier `typing.ClassVar` is not allowed in type alias values +classes_classvar.py:89:8: error[invalid-type-form] `ClassVar` is not allowed in TypedDict fields +classes_classvar.py:94:5: error[invalid-named-tuple] Type qualifier `ClassVar` is not allowed on NamedTuple field `b` +classes_classvar.py:127:1: error[invalid-attribute-access] Cannot assign to ClassVar `stats` from an instance of type `Starship` +classes_classvar.py:156:13: error[invalid-assignment] Object of type `ProtoAImpl` is not assignable to `ProtoA` """ diff --git a/conformance/results/ty/qualifiers_final_annotation.toml b/conformance/results/ty/qualifiers_final_annotation.toml index 10678afda..ba871f898 100644 --- a/conformance/results/ty/qualifiers_final_annotation.toml +++ b/conformance/results/ty/qualifiers_final_annotation.toml @@ -18,16 +18,18 @@ qualifiers_final_annotation.py:107:13: error[redundant-final-classvar] `Combinin qualifiers_final_annotation.py:108:13: error[redundant-final-classvar] `Combining `ClassVar` and `Final` is redundant qualifiers_final_annotation.py:118:9: error[invalid-type-form] Type qualifier `typing.Final` is not allowed in type expressions (only in annotation expressions) qualifiers_final_annotation.py:121:14: error[invalid-type-form] Type qualifier `typing.Final` is not allowed in parameter annotations -qualifiers_final_annotation.py:134:1: error[missing-argument] No arguments provided for required parameters `x`, `y` -qualifiers_final_annotation.py:134:3: error[unknown-argument] Argument `a` does not match any known parameter -qualifiers_final_annotation.py:135:3: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]` -qualifiers_final_annotation.py:135:9: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]` -qualifiers_final_annotation.py:141:5: error[invalid-assignment] Reassignment of `Final` symbol `ID1` is not allowed: Reassignment of `Final` symbol -qualifiers_final_annotation.py:145:5: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here -qualifiers_final_annotation.py:147:10: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here -qualifiers_final_annotation.py:149:9: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here -qualifiers_final_annotation.py:152:30: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here -qualifiers_final_annotation.py:155:9: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here -qualifiers_final_annotation.py:166:1: error[invalid-assignment] Reassignment of `Final` symbol `TEN` is not allowed: Reassignment of `Final` symbol -qualifiers_final_annotation.py:170:1: error[invalid-assignment] Reassignment of `Final` symbol `PI` is not allowed: Reassignment of `Final` symbol +qualifiers_final_annotation.py:131:8: error[invalid-type-form] `Final` is not allowed in TypedDict fields +qualifiers_final_annotation.py:136:5: error[invalid-named-tuple] Type qualifier `Final` is not allowed on NamedTuple field `b` +qualifiers_final_annotation.py:148:1: error[missing-argument] No arguments provided for required parameters `x`, `y` +qualifiers_final_annotation.py:148:3: error[unknown-argument] Argument `a` does not match any known parameter +qualifiers_final_annotation.py:149:3: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]` +qualifiers_final_annotation.py:149:9: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `Literal[""]` +qualifiers_final_annotation.py:155:5: error[invalid-assignment] Reassignment of `Final` symbol `ID1` is not allowed: Reassignment of `Final` symbol +qualifiers_final_annotation.py:159:5: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here +qualifiers_final_annotation.py:161:10: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here +qualifiers_final_annotation.py:163:9: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here +qualifiers_final_annotation.py:166:30: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here +qualifiers_final_annotation.py:169:9: error[invalid-assignment] Reassignment of `Final` symbol `x` is not allowed: Symbol later reassigned here +qualifiers_final_annotation.py:180:1: error[invalid-assignment] Reassignment of `Final` symbol `TEN` is not allowed: Reassignment of `Final` symbol +qualifiers_final_annotation.py:184:1: error[invalid-assignment] Reassignment of `Final` symbol `PI` is not allowed: Reassignment of `Final` symbol """ diff --git a/conformance/results/zuban/classes_classvar.toml b/conformance/results/zuban/classes_classvar.toml index a451ac506..afb724d07 100644 --- a/conformance/results/zuban/classes_classvar.toml +++ b/conformance/results/zuban/classes_classvar.toml @@ -2,26 +2,28 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ -classes_classvar.py:38: error: ClassVar[...] must have at most one type argument [misc] -classes_classvar.py:39: error: Invalid type: try using Literal[3] instead? [valid-type] -classes_classvar.py:40: error: Name "var" is not defined [name-defined] -classes_classvar.py:45: error: ClassVar cannot contain type variables [misc] -classes_classvar.py:46: error: ClassVar cannot contain type variables [misc] +classes_classvar.py:40: error: ClassVar[...] must have at most one type argument [misc] +classes_classvar.py:41: error: Invalid type: try using Literal[3] instead? [valid-type] +classes_classvar.py:42: error: Name "var" is not defined [name-defined] classes_classvar.py:47: error: ClassVar cannot contain type variables [misc] -classes_classvar.py:52: error: Incompatible types in assignment (expression has type "dict[Any, Any]", variable has type "list[str]") [assignment] -classes_classvar.py:54: error: Variable should not be annotated with both ClassVar and Final [misc] -classes_classvar.py:55: error: Invalid Type: ClassVar nested inside other type [misc] -classes_classvar.py:66: error: Type in ClassVar[...] can only be omitted if there is an initializer [misc] -classes_classvar.py:69: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:70: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:48: error: ClassVar cannot contain type variables [misc] +classes_classvar.py:49: error: ClassVar cannot contain type variables [misc] +classes_classvar.py:54: error: Incompatible types in assignment (expression has type "dict[Any, Any]", variable has type "list[str]") [assignment] +classes_classvar.py:56: error: Variable should not be annotated with both ClassVar and Final [misc] +classes_classvar.py:57: error: Invalid Type: ClassVar nested inside other type [misc] +classes_classvar.py:68: error: Type in ClassVar[...] can only be omitted if there is an initializer [misc] classes_classvar.py:71: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:72: error: ClassVar can only be used for assignments in class body [misc] classes_classvar.py:73: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:77: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:78: error: ClassVar can only be used for assignments in class body [misc] -classes_classvar.py:111: error: Cannot assign to class variable "stats" via instance [misc] -classes_classvar.py:140: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment] -classes_classvar.py:140: note: Protocol member ProtoA.x expected class variable, got instance variable -classes_classvar.py:140: note: Protocol member ProtoA.y expected class variable, got instance variable -classes_classvar.py:140: note: "ProtoAImpl" is missing following "ProtoA" protocol member: -classes_classvar.py:140: note: z +classes_classvar.py:75: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:79: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:80: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:89: error: Invalid Type: ClassVar nested inside other type [misc] +classes_classvar.py:94: error: ClassVar can only be used for assignments in class body [misc] +classes_classvar.py:127: error: Cannot assign to class variable "stats" via instance [misc] +classes_classvar.py:156: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment] +classes_classvar.py:156: note: Protocol member ProtoA.x expected class variable, got instance variable +classes_classvar.py:156: note: Protocol member ProtoA.y expected class variable, got instance variable +classes_classvar.py:156: note: "ProtoAImpl" is missing following "ProtoA" protocol member: +classes_classvar.py:156: note: z """ diff --git a/conformance/results/zuban/qualifiers_final_annotation.toml b/conformance/results/zuban/qualifiers_final_annotation.toml index 32a15ea44..1101ba386 100644 --- a/conformance/results/zuban/qualifiers_final_annotation.toml +++ b/conformance/results/zuban/qualifiers_final_annotation.toml @@ -18,16 +18,18 @@ qualifiers_final_annotation.py:107: error: Final can be only used as an outermos qualifiers_final_annotation.py:108: error: Invalid Type: ClassVar nested inside other type [misc] qualifiers_final_annotation.py:118: error: Final can be only used as an outermost qualifier in a variable annotation [misc] qualifiers_final_annotation.py:121: error: Final can be only used as an outermost qualifier in a variable annotation [misc] -qualifiers_final_annotation.py:134: error: Unexpected keyword argument "a" for "N" [call-arg] -qualifiers_final_annotation.py:135: error: Argument "x" to "N" has incompatible type "str"; expected "int" [arg-type] -qualifiers_final_annotation.py:135: error: Argument "y" to "N" has incompatible type "str"; expected "int" [arg-type] -qualifiers_final_annotation.py:141: error: Cannot assign to final name "ID1" [misc] -qualifiers_final_annotation.py:145: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:147: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:149: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:152: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:152: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "int") [assignment] -qualifiers_final_annotation.py:155: error: Cannot assign to final name "x" [misc] -qualifiers_final_annotation.py:166: error: Cannot assign to final name "TEN" [misc] -qualifiers_final_annotation.py:170: error: Cannot assign to final name "PI" [misc] +qualifiers_final_annotation.py:131: error: Final can be only used as an outermost qualifier in a variable annotation [misc] +qualifiers_final_annotation.py:136: error: Final can be only used as an outermost qualifier in a variable annotation [misc] +qualifiers_final_annotation.py:148: error: Unexpected keyword argument "a" for "N" [call-arg] +qualifiers_final_annotation.py:149: error: Argument "x" to "N" has incompatible type "str"; expected "int" [arg-type] +qualifiers_final_annotation.py:149: error: Argument "y" to "N" has incompatible type "str"; expected "int" [arg-type] +qualifiers_final_annotation.py:155: error: Cannot assign to final name "ID1" [misc] +qualifiers_final_annotation.py:159: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:161: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:163: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:166: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:166: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "int") [assignment] +qualifiers_final_annotation.py:169: error: Cannot assign to final name "x" [misc] +qualifiers_final_annotation.py:180: error: Cannot assign to final name "TEN" [misc] +qualifiers_final_annotation.py:184: error: Cannot assign to final name "PI" [misc] """ diff --git a/conformance/tests/classes_classvar.py b/conformance/tests/classes_classvar.py index 3f94fe5a6..5f0ca9241 100644 --- a/conformance/tests/classes_classvar.py +++ b/conformance/tests/classes_classvar.py @@ -11,11 +11,13 @@ ClassVar, Final, Generic, + NamedTuple, ParamSpec, Protocol, TypeAlias, TypeVar, TypeVarTuple, + TypedDict, assert_type, cast, ) @@ -78,6 +80,20 @@ def method2(self) -> ClassVar[int]: # E: ClassVar not allowed here bad12: TypeAlias = ClassVar[str] # E: ClassVar not allowed here +# > ``ClassVar`` cannot be used as a qualifier for a TypedDict item or a +# > NamedTuple field. Such usage also generates an error at runtime. + + +class TDWithClassVar(TypedDict): + a: int + b: ClassVar[int] # E: ClassVar not allowed in a TypedDict + + +class NTWithClassVar(NamedTuple): + a: int + b: ClassVar[int] # E: ClassVar not allowed in a NamedTuple + + assert_type(ClassA.good1, int) assert_type(ClassA.good2, list[str]) assert_type(ClassA.good3, Any) diff --git a/conformance/tests/qualifiers_final_annotation.py b/conformance/tests/qualifiers_final_annotation.py index 822ea564a..0dc611211 100644 --- a/conformance/tests/qualifiers_final_annotation.py +++ b/conformance/tests/qualifiers_final_annotation.py @@ -2,7 +2,7 @@ Tests the typing.Final special form. """ -from typing import ClassVar, Final, Literal, NamedTuple, assert_type +from typing import ClassVar, Final, Literal, NamedTuple, TypedDict, assert_type # Specification: https://typing.readthedocs.io/en/latest/spec/qualifiers.html#id1 @@ -122,6 +122,20 @@ def func1(x: Final[list[int]]) -> None: # E ... +# > ``Final`` cannot be used as a qualifier for a TypedDict item or a +# > NamedTuple field. Such usage also generates an error at runtime. + + +class TDWithFinal(TypedDict): + a: int + b: Final[int] # E: Final not allowed in a TypedDict + + +class NTWithFinal(NamedTuple): + a: int + b: Final[int] # E: Final not allowed in a NamedTuple + + # > Type checkers should treat uses of a final name that was initialized with # > a literal as if it was replaced by the literal. For example, the following # > should be allowed: