Skip to content

Commit

Permalink
Added link to conformance results.
Browse files Browse the repository at this point in the history
Added tests for `@final` decorator.

Added tests for `Final` annotation.

Updated pyright test results for latest version (1.1.344).

Added tests for Annotated.
  • Loading branch information
erictraut committed Dec 30, 2023
1 parent 8aa8f8b commit a6b4ad6
Show file tree
Hide file tree
Showing 30 changed files with 826 additions and 82 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This GitHub repository is used for several things:
- A [discussion forum](https://github.com/python/typing/discussions) for typing-related user
help is hosted here.

- [Conformance test](https://github.com/python/typing/blob/main/conformance/README.md) for Python static type checkers. The [latest conformance test results](https://htmlpreview.github.io/?https://github.com/python/typing/blob/main/conformance/results/results.html) are here.

Historically, this repository also hosted:

- The `typing_extensions` package, which now lives in the
Expand Down
26 changes: 26 additions & 0 deletions conformance/results/mypy/qualifiers_annotated.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
conformant = "Partial"
notes = """
Does not allow ClassVar to be nested within Annotated.
Does not allow Final to be nested within Annotated.
Does not allow Required and NotRequired to be nested within Annotated.
"""
output = """
qualifiers_annotated.py:41: error: Bracketed expression "[...]" is not valid as a type [valid-type]
qualifiers_annotated.py:42: error: Syntax error in type annotation [syntax]
qualifiers_annotated.py:42: note: Suggestion: Is there a spurious trailing comma?
qualifiers_annotated.py:43: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:44: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:45: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:46: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:47: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:48: error: Name "var1" is not defined [name-defined]
qualifiers_annotated.py:49: error: Invalid type: try using Literal[True] instead? [valid-type]
qualifiers_annotated.py:50: error: Invalid type: try using Literal[1] instead? [valid-type]
qualifiers_annotated.py:51: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:52: error: Invalid type comment or annotation [valid-type]
qualifiers_annotated.py:62: error: Annotated[...] must have exactly one type argument and at least one annotation [valid-type]
qualifiers_annotated.py:73: error: Invalid type: ClassVar nested inside other type [valid-type]
qualifiers_annotated.py:75: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
qualifiers_annotated.py:85: error: Required[] can be only used in a TypedDict definition [valid-type]
qualifiers_annotated.py:87: error: NotRequired[] can be only used in a TypedDict definition [valid-type]
"""
38 changes: 38 additions & 0 deletions conformance/results/mypy/qualifiers_final_annotation.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
conformant = "Partial"
notes = """
Does not treat use of Final name as if it was replaced by the literal in NamedTuple definition.
Does not allow conditional assignment of Final instance variable in __init__ method.
Does not allow redefinition of private class variable that is marked Final in parent class.
Does not report modification of local Final variable via "for" statement.
"""
output = """
qualifiers_final_annotation.py:16: error: Type in Final[...] can only be omitted if there is an initializer [misc]
qualifiers_final_annotation.py:18: error: Final[...] takes at most one type argument [misc]
qualifiers_final_annotation.py:34: error: Type in Final[...] can only be omitted if there is an initializer [misc]
qualifiers_final_annotation.py:38: error: Final name must be initialized with a value [misc]
qualifiers_final_annotation.py:54: error: Cannot assign to final attribute "ID5" [misc]
qualifiers_final_annotation.py:59: error: Cannot assign to final attribute "ID6" [misc]
qualifiers_final_annotation.py:62: error: Can only declare a final attribute in class body or __init__ [misc]
qualifiers_final_annotation.py:63: error: Can only declare a final attribute in class body or __init__ [misc]
qualifiers_final_annotation.py:65: error: Cannot assign to final attribute "ID7" [misc]
qualifiers_final_annotation.py:67: error: Cannot assign to final attribute "ID7" [misc]
qualifiers_final_annotation.py:71: error: Cannot assign to final name "RATE" [misc]
qualifiers_final_annotation.py:81: error: Cannot assign to final attribute "DEFAULT_ID" [misc]
qualifiers_final_annotation.py:94: error: Cannot assign to final name "BORDER_WIDTH" [misc]
qualifiers_final_annotation.py:96: error: Cannot assign to final name "__private" [misc]
qualifiers_final_annotation.py:107: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
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", variable has type "int") [assignment]
qualifiers_final_annotation.py:155: error: Cannot assign to final name "x" [misc]
"""
17 changes: 17 additions & 0 deletions conformance/results/mypy/qualifiers_final_decorator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
conformant = "Pass"
output = """
qualifiers_final_decorator.py:21: error: Cannot inherit from final class "Base1" [misc]
qualifiers_final_decorator.py:56: error: Cannot override final attribute "method1" (previously declared in base class "Base2") [misc]
qualifiers_final_decorator.py:59: error: Cannot override final attribute "method2" (previously declared in base class "Base2") [misc]
qualifiers_final_decorator.py:63: error: Cannot override final attribute "method3" (previously declared in base class "Base2") [misc]
qualifiers_final_decorator.py:67: error: Cannot override final attribute "method4" (previously declared in base class "Base2") [misc]
qualifiers_final_decorator.py:80: error: Cannot override final attribute "method" (previously declared in base class "Base3") [misc]
qualifiers_final_decorator.py:93: error: Cannot override final attribute "method" (previously declared in base class "Base4") [misc]
qualifiers_final_decorator.py:117: error: Cannot override final attribute "method" (previously declared in base class "Base5_2") [misc]
qualifiers_final_decorator.py:117: error: Signature of "method" incompatible with supertype "Base5_2" [override]
qualifiers_final_decorator.py:117: note: Superclass:
qualifiers_final_decorator.py:117: note: def method(self, v: int) -> None
qualifiers_final_decorator.py:117: note: Subclass:
qualifiers_final_decorator.py:117: note: def method(self) -> None
qualifiers_final_decorator.py:124: error: @final cannot be used with non-method functions [misc]
"""
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.8.0"
test_duration = 0.3814089298248291
test_duration = 0.4777989387512207
18 changes: 18 additions & 0 deletions conformance/results/pyre/qualifiers_annotated.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
conformant = "Partial"
notes = """
Does not reject Annotated with a single parameter.
"""
output = """
qualifiers_annotated.py:41:6 Undefined or invalid type [11]: Annotation `` is not defined as a type.
qualifiers_annotated.py:42:6 Invalid type [31]: Expression `typing.Annotated[(((int, str)), "")]` is not a valid type.
qualifiers_annotated.py:43:6 Invalid type [31]: Expression `typing.Annotated[(comprehension(int for generators(generator($target$i in range(1) if ))), "")]` is not a valid type.
qualifiers_annotated.py:44:6 Invalid type [31]: Expression `typing.Annotated[({ "a":"b" }, "")]` is not a valid type.
qualifiers_annotated.py:45:6 Invalid type [31]: Expression `typing.Annotated[(lambda () (int)(), "")]` is not a valid type.
qualifiers_annotated.py:46:6 Invalid type [31]: Expression `typing.Annotated[([int][0], "")]` is not a valid type.
qualifiers_annotated.py:47:6 Invalid type [31]: Expression `typing.Annotated[(int if 1 < 3 else str, "")]` is not a valid type.
qualifiers_annotated.py:48:16 Unbound name [10]: Name `var1` is used but not defined in the current scope.
qualifiers_annotated.py:49:6 Invalid type [31]: Expression `typing.Annotated[(True, "")]` is not a valid type.
qualifiers_annotated.py:50:7 Invalid type [31]: Expression `typing.Annotated[(1, "")]` is not a valid type.
qualifiers_annotated.py:51:7 Invalid type [31]: Expression `typing.Annotated[(list or set, "")]` is not a valid type.
qualifiers_annotated.py:52:7 Invalid type [31]: Expression `typing.Annotated[(f"{"int"}", "")]` is not a valid type.
"""
34 changes: 34 additions & 0 deletions conformance/results/pyre/qualifiers_final_annotation.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
conformant = "Partial"
notes = """
Does not report Final variable with missing initialization in module scope.
Does not report error for invalid nesting of Final and ClassVar.
Does not treat use of Final name as if it was replaced by the literal in NamedTuple definition.
"""
output = """
qualifiers_final_annotation.py:18:6 Invalid type parameters [24]: Generic type `Final` expects 1 type parameter, received 2.
qualifiers_final_annotation.py:28:0 Uninitialized attribute [13]: Attribute `ID3` is declared in class `ClassA` to have type `int` but is never initialized.
qualifiers_final_annotation.py:34:4 Invalid assignment [41]: Cannot reassign final attribute `ClassA.ID2`.
qualifiers_final_annotation.py:54:8 Invalid assignment [41]: Cannot reassign final attribute `self.ID5`.
qualifiers_final_annotation.py:62:8 Undefined attribute [16]: `ClassA` has no attribute `id3`.
qualifiers_final_annotation.py:63:8 Undefined attribute [16]: `ClassA` has no attribute `id4`.
qualifiers_final_annotation.py:65:8 Invalid assignment [41]: Cannot reassign final attribute `self.ID7`.
qualifiers_final_annotation.py:67:8 Invalid assignment [41]: Cannot reassign final attribute `self.ID7`.
qualifiers_final_annotation.py:71:0 Invalid assignment [41]: Cannot reassign final attribute `RATE`.
qualifiers_final_annotation.py:81:0 Invalid assignment [41]: Cannot reassign final attribute `ClassB.DEFAULT_ID`.
qualifiers_final_annotation.py:94:4 Invalid assignment [41]: Cannot reassign final attribute `BORDER_WIDTH`.
qualifiers_final_annotation.py:107:4 Incompatible attribute type [8]: Attribute `VALUE2` declared in class `ClassD` has type `Final` but is used as type `int`.
qualifiers_final_annotation.py:107:4 Invalid type [31]: Expression `Final` is not a valid type. Final cannot be nested.
qualifiers_final_annotation.py:118:0 Invalid type [31]: Expression `typing.List[Final[int]]` is not a valid type. Final cannot be nested.
qualifiers_final_annotation.py:121:10 Invalid type [31]: Parameter `x` cannot be annotated with Final.
qualifiers_final_annotation.py:131:0 Uninitialized attribute [13]: Attribute `($local_qualifiers_final_annotation$X, int)` is declared in class `N` to have type `typing.Any` but is never initialized.
qualifiers_final_annotation.py:131:0 Uninitialized attribute [13]: Attribute `($local_qualifiers_final_annotation$Y, int)` is declared in class `N` to have type `typing.Any` but is never initialized.
qualifiers_final_annotation.py:133:0 Unexpected keyword [28]: Unexpected keyword argument `x` to call `N.__init__`.
qualifiers_final_annotation.py:134:0 Unexpected keyword [28]: Unexpected keyword argument `a` to call `N.__init__`.
qualifiers_final_annotation.py:135:0 Unexpected keyword [28]: Unexpected keyword argument `x` to call `N.__init__`.
qualifiers_final_annotation.py:141:4 Invalid assignment [41]: Cannot reassign final attribute `ID1`.
qualifiers_final_annotation.py:145:4 Invalid assignment [41]: Cannot reassign final attribute `x`.
qualifiers_final_annotation.py:147:9 Invalid assignment [41]: Cannot reassign final attribute `x`.
qualifiers_final_annotation.py:149:8 Invalid assignment [41]: Cannot reassign final attribute `x`.
qualifiers_final_annotation.py:152:29 Invalid assignment [41]: Cannot reassign final attribute `x`.
qualifiers_final_annotation.py:155:8 Invalid assignment [41]: Cannot reassign final attribute `x`.
"""
16 changes: 16 additions & 0 deletions conformance/results/pyre/qualifiers_final_decorator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
conformant = "Partial"
notes = """
Reports error for overloaded method implementation marked @final if its overloads do not.
Does not report error for overloaded @final method defined in stub file.
"""
output = """
qualifiers_final_decorator.py:21:0 Invalid inheritance [39]: Cannot inherit from final class `Base1`.
qualifiers_final_decorator.py:51:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
qualifiers_final_decorator.py:56:4 Invalid override [40]: `qualifiers_final_decorator.Derived2.method1` cannot override final method defined in `Base2`.
qualifiers_final_decorator.py:60:4 Invalid override [40]: `qualifiers_final_decorator.Derived2.method2` cannot override final method defined in `Base2`.
qualifiers_final_decorator.py:64:4 Invalid override [40]: `qualifiers_final_decorator.Derived2.method3` cannot override final method defined in `Base2`.
qualifiers_final_decorator.py:75:4 Invalid override [40]: `qualifiers_final_decorator.Derived2.method4` cannot override final method defined in `Base2`.
qualifiers_final_decorator.py:117:4 Inconsistent override [14]: `qualifiers_final_decorator.Derived5.method` overrides method defined in `Base5_2` inconsistently. Could not find parameter `v` in overriding signature.
qualifiers_final_decorator.py:117:4 Invalid override [40]: `qualifiers_final_decorator.Derived5.method` cannot override final method defined in `Base5_2`.
qualifiers_final_decorator.py:125:0 Invalid inheritance [39]: `final` cannot be used with non-method functions.
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyre 0.9.19"
test_duration = 1.5496571063995361
test_duration = 1.6688978672027588
10 changes: 3 additions & 7 deletions conformance/results/pyright/aliases_explicit.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
conformant = "Partial"
notes = """
Incorrectly evaluates type of specialized type alias parameterized with ParamSpec.
Allows some illegal annotation forms to be interpreted as valid type aliases.
"""
conformant = "Pass"
output = """
aliases_explicit.py:57:17 - error: "assert_type" mismatch: expected "(int, str, str) -> None" but received "(int, str, str) -> None" (reportGeneralTypeIssues)
aliases_explicit.py:67:24 - error: Expected no type arguments for class "int" (reportGeneralTypeIssues)
aliases_explicit.py:67:24 - error: Expected no type arguments for class "NoneType" (reportGeneralTypeIssues)
aliases_explicit.py:68:9 - error: Type "list[int | None]" is already specialized (reportGeneralTypeIssues)
Expand All @@ -20,7 +15,6 @@ aliases_explicit.py:80:21 - error: Expected type expression but received "list[U
aliases_explicit.py:81:21 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:81:21 - error: Tuple expression not allowed in type annotation
  Use Tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportGeneralTypeIssues)
aliases_explicit.py:81:21 - error: Expected type expression but received "tuple[tuple[type[int], type[str]]]" (reportGeneralTypeIssues)
aliases_explicit.py:82:21 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:82:21 - error: List expression not allowed in type annotation
  Use List[T] to indicate a list type or Union[T1, T2] to indicate a union type (reportGeneralTypeIssues)
Expand All @@ -31,6 +25,7 @@ aliases_explicit.py:83:21 - error: Dictionary expression not allowed in type ann
aliases_explicit.py:83:21 - error: Expected type expression but received "dict[str, str]" (reportGeneralTypeIssues)
aliases_explicit.py:84:21 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:84:21 - error: Call expression not allowed in type expression (reportGeneralTypeIssues)
aliases_explicit.py:85:21 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:85:21 - error: List expression not allowed in type annotation
  Use List[T] to indicate a list type or Union[T1, T2] to indicate a union type (reportGeneralTypeIssues)
aliases_explicit.py:85:21 - error: Expected type expression but received "list[type[int]]" (reportGeneralTypeIssues)
Expand All @@ -40,6 +35,7 @@ aliases_explicit.py:87:21 - error: Variable not allowed in type expression (repo
aliases_explicit.py:88:22 - error: Expected type expression but received "Literal[True]" (reportGeneralTypeIssues)
aliases_explicit.py:89:22 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:89:22 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues)
aliases_explicit.py:90:22 - error: Invalid expression form for type alias definition (reportGeneralTypeIssues)
aliases_explicit.py:90:22 - error: Binary operator not allowed in type annotation
aliases_explicit.py:91:22 - error: Expected expression
aliases_explicit.py:91:22 - error: Tuple expression not allowed in type annotation
Expand Down
10 changes: 4 additions & 6 deletions conformance/results/pyright/aliases_implicit.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
conformant = "Partial"
notes = """
Incorrectly evaluates type of specialized type alias parameterized with ParamSpec.
Allows some illegal annotation forms to be interpreted as valid type aliases.
"""
conformant = "Pass"
output = """
aliases_implicit.py:68:17 - error: "assert_type" mismatch: expected "(int, str, str) -> None" but received "(int, str, str) -> None" (reportGeneralTypeIssues)
aliases_implicit.py:76:24 - error: Expected no type arguments for class "int" (reportGeneralTypeIssues)
aliases_implicit.py:76:24 - error: Expected no type arguments for class "NoneType" (reportGeneralTypeIssues)
aliases_implicit.py:77:9 - error: Type "list[int | None]" is already specialized (reportGeneralTypeIssues)
Expand All @@ -19,10 +14,13 @@ aliases_implicit.py:107:9 - error: Variable not allowed in type expression (repo
aliases_implicit.py:108:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:109:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:110:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:111:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:112:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:113:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:114:9 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:115:10 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:116:10 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:117:10 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:118:10 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:119:10 - error: Variable not allowed in type expression (reportGeneralTypeIssues)
aliases_implicit.py:133:6 - error: Object of type "type[list[Unknown]] | type[set[Unknown]]" is not callable (reportGeneralTypeIssues)
Expand Down
Loading

0 comments on commit a6b4ad6

Please sign in to comment.