Skip to content

Commit

Permalink
Merge branch 'main' into concepts
Browse files Browse the repository at this point in the history
* main:
  Adds links to Python Discourse and ruff to typing.readthedocs.io (python#1774)
  Conformance tests: Mark pytype as passing annotations_coroutines (python#1771)
  Conformance tests: Fix manual scoring discrepancy for pyre (python#1770)
  Updated conformance test results for pyright 1.1.366. (python#1768)
  Spec: "Distributing type information": add links to PEPs 484 and 561; add a new anchor for easy intersphinx referencing (python#1767)
  Implemented conformance tests for Enums chapter. (python#1764)
  Fixed two bugs in the conformance test: (python#1763)
  Fixed two small typos in Enums chapter that I discovered when writing… (python#1762)
  Typo fix: Replace `TypeVar` with `TypeVarTuple` in a docs example (python#1760)
  Added draft chapter to typing spec for enumerations. (python#1759)
  List pip as an explicit dependency for the conformance tests (python#1757)
  • Loading branch information
carljm committed Jun 12, 2024
2 parents 5d40036 + ab3e82d commit 1e0d118
Show file tree
Hide file tree
Showing 61 changed files with 1,368 additions and 60 deletions.
1 change: 1 addition & 0 deletions conformance/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ tomlkit
tqdm
pyright
mypy
pip
pyre-check
pytype; platform_system != "Windows"
5 changes: 5 additions & 0 deletions conformance/results/mypy/constructors_consistency.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ conformant = "Pass"
notes = """
Does not report inconsistency between __new__ and __init__ (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
"""
7 changes: 7 additions & 0 deletions conformance/results/mypy/enums_behaviors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
conformant = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39: error: Cannot extend enum with existing members: "Shape" [misc]
"""
conformance_automated = "Pass"
6 changes: 6 additions & 0 deletions conformance/results/mypy/enums_definition.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Pass"
errors_diff = """
"""
output = """
"""
conformance_automated = "Pass"
12 changes: 12 additions & 0 deletions conformance/results/mypy/enums_expansion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
conformant = "Partial"
notes = """
Improperly applies narrowing to Flag subclass.
"""
conformance_automated = "Fail"
errors_diff = """
Line 53: Expected 1 errors
Line 52: Unexpected errors ['enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]']
"""
output = """
enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/enums_member_names.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
conformant = "Pass"
notes = """
Does not support special-cased handling of member name literal types in some cases (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_member_names.py:26: error: Expression is of type "str", not "Literal['RED', 'BLUE']" [assert-type]
enums_member_names.py:30: error: Expression is of type "str", not "Literal['RED', 'BLUE', 'GREEN']" [assert-type]
"""
16 changes: 16 additions & 0 deletions conformance/results/mypy/enums_member_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
conformant = "Partial"
notes = """
Does not enforce declared type of `_value_`.
Does not enforce assigned tuple types for enum members (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 78: Expected 1 errors
"""
output = """
enums_member_values.py:26: error: Expression is of type "Any", not "Literal[1, 3]" [assert-type]
enums_member_values.py:54: error: Expression is of type "tuple[int, float, float]", not "Literal[1]" [assert-type]
enums_member_values.py:68: error: Expression is of type "int", not "Literal[1]" [assert-type]
enums_member_values.py:85: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
enums_member_values.py:96: error: Expression is of type "EllipsisType", not "int" [assert-type]
"""
42 changes: 42 additions & 0 deletions conformance/results/mypy/enums_members.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
conformant = "Partial"
notes = """
Does not treat attribute with annotation and no assignment as non-member.
Does not reject use of annotation with enum member.
Does not treat callables as non-members.
Does not honor `enum.nonmember` to define non-member attribute.
Does not honor `enum.member` as method decorator.
Does not properly handle aliased enum members.
Does not support `_ignore_` mechanism (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 46: Expected 1 errors
Line 78: Expected 1 errors
Line 79: Expected 1 errors
Line 112: Expected 1 errors
Line 23: Unexpected errors ['enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]']
Line 24: Unexpected errors ['enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]']
Line 31: Unexpected errors ['enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]']
Line 32: Unexpected errors ['enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]']
Line 96: Unexpected errors ['enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]']
Line 113: Unexpected errors ['enums_members.py:113: error: Expression is of type "member[Callable[[Example], None]]", not "Any" [assert-type]', 'enums_members.py:113: error: Parameter 1 of Literal[...] is invalid [valid-type]']
"""
output = """
enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]
enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]
enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]
enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]
enums_members.py:80: error: Expression is of type "Callable[[Pet4], str]", not "Any" [assert-type]
enums_members.py:80: error: Parameter 1 of Literal[...] is invalid [valid-type]
enums_members.py:81: error: Expression is of type "Callable[[Pet4], None]", not "Any" [assert-type]
enums_members.py:81: error: Parameter 1 of Literal[...] is invalid [valid-type]
enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]
enums_members.py:113: error: Expression is of type "member[Callable[[Example], None]]", not "Any" [assert-type]
enums_members.py:113: error: Parameter 1 of Literal[...] is invalid [valid-type]
enums_members.py:124: note: Revealed type is "Any"
enums_members.py:124: note: 'reveal_type' always outputs 'Any' in unchecked functions
enums_members.py:125: error: Expression is of type "Any", not "Literal[Example2.__B]" [assert-type]
enums_members.py:125: note: "assert_type" expects everything to be "Any" in unchecked functions
enums_members.py:142: error: Expression is of type "Literal[Pet5.DOG]", not "int" [assert-type]
enums_members.py:143: error: Expression is of type "Literal[Pet5.FISH]", not "int" [assert-type]
"""
1 change: 1 addition & 0 deletions conformance/results/mypy/exceptions_context_managers.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ errors_diff = """
"""
output = """
"""
conformance_automated = "Pass"
14 changes: 7 additions & 7 deletions conformance/results/mypy/generics_paramspec_semantics.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ generics_paramspec_semantics.py:26: error: Unexpected keyword argument "a" [cal
generics_paramspec_semantics.py:26: error: Unexpected keyword argument "b" [call-arg]
generics_paramspec_semantics.py:27: error: Argument 2 has incompatible type "str"; expected "bool" [arg-type]
generics_paramspec_semantics.py:61: error: Argument 2 to "func1" has incompatible type "Callable[[NamedArg(int, 'y')], int]"; expected "Callable[[NamedArg(int, 'x')], int]" [arg-type]
generics_paramspec_semantics.py:97: error: Argument 1 has incompatible type "int"; expected "str" [arg-type]
generics_paramspec_semantics.py:107: error: Argument 1 has incompatible type "int"; expected "bool" [arg-type]
generics_paramspec_semantics.py:119: error: Argument 1 has incompatible type "int"; expected "str" [arg-type]
generics_paramspec_semantics.py:126: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" [arg-type]
generics_paramspec_semantics.py:126: note: This is likely because "one" has named arguments: "x". Consider marking them positional-only
generics_paramspec_semantics.py:131: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, NamedArg(int, 'x')], int]" [arg-type]
generics_paramspec_semantics.py:136: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[KwArg(int)], int]"; expected "Callable[[int, KwArg(int)], int]" [arg-type]
generics_paramspec_semantics.py:98: error: Argument 1 has incompatible type "int"; expected "str" [arg-type]
generics_paramspec_semantics.py:108: error: Argument 1 has incompatible type "int"; expected "bool" [arg-type]
generics_paramspec_semantics.py:120: error: Argument 1 has incompatible type "int"; expected "str" [arg-type]
generics_paramspec_semantics.py:127: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" [arg-type]
generics_paramspec_semantics.py:127: note: This is likely because "one" has named arguments: "x". Consider marking them positional-only
generics_paramspec_semantics.py:132: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, NamedArg(int, 'x')], int]" [arg-type]
generics_paramspec_semantics.py:137: error: Argument 1 to "expects_int_first" has incompatible type "Callable[[KwArg(int)], int]"; expected "Callable[[int, KwArg(int)], int]" [arg-type]
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
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.10.0"
test_duration = 1.5
test_duration = 1.1
1 change: 1 addition & 0 deletions conformance/results/pyre/constructors_call_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ constructors_call_type.py:72:4 Missing argument [20]: Call `Meta1.__call__` expe
constructors_call_type.py:81:4 Missing argument [20]: Call `Class2.__new__` expects argument `y`.
constructors_call_type.py:82:11 Incompatible parameter type [6]: In call `Class2.__new__`, for 2nd positional argument, expected `str` but got `int`.
"""
conformance_automated = "Pass"
5 changes: 5 additions & 0 deletions conformance/results/pyre/constructors_consistency.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ conformant = "Pass"
notes = """
Does not report inconsistency between __new__ and __init__ (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
"""
10 changes: 10 additions & 0 deletions conformance/results/pyre/enums_behaviors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
conformant = "Partial"
notes = """
Does not enforce that Enum classes are implicitly final.
"""
conformance_automated = "Fail"
errors_diff = """
Line 39: Expected 1 errors
"""
output = """
"""
19 changes: 19 additions & 0 deletions conformance/results/pyre/enums_definition.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
conformant = "Partial"
notes = """
Does not support custom Enum classes based on EnumType metaclass.
Does not support some functional forms for Enum class definitions (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 75: Unexpected errors ['enums_definition.py:75:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color11.RED]` but got `int`.']
"""
output = """
enums_definition.py:24:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 4 were provided.
enums_definition.py:27:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:28:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:31:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:33:12 Undefined attribute [16]: `Enum` has no attribute `RED`.
enums_definition.py:38:12 Undefined attribute [16]: `Color7` has no attribute `RED`.
enums_definition.py:39:12 Undefined attribute [16]: `Color8` has no attribute `RED`.
enums_definition.py:75:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color11.RED]` but got `int`.
"""
12 changes: 12 additions & 0 deletions conformance/results/pyre/enums_expansion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
conformant = "Pass"
notes = """
Does not perform type narrowing based on enum literal expansion (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_expansion.py:25:8 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color.GREEN]` but got `Color`.
enums_expansion.py:35:12 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Never` but got `Color`.
enums_expansion.py:53:8 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[CustomFlags.FLAG3]` but got `CustomFlags`.
"""
13 changes: 13 additions & 0 deletions conformance/results/pyre/enums_member_names.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
conformant = "Pass"
notes = """
Does not support special-cased handling of member name literal types (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_member_names.py:21:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal['RED']` but got `str`.
enums_member_names.py:22:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal['RED']` but got `typing.Any`.
enums_member_names.py:26:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal['BLUE'], typing_extensions.Literal['RED']]` but got `typing.Any`.
enums_member_names.py:30:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal['BLUE'], typing_extensions.Literal['GREEN'], typing_extensions.Literal['RED']]` but got `typing.Any`.
"""
23 changes: 23 additions & 0 deletions conformance/results/pyre/enums_member_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
conformant = "Partial"
notes = """
Does not enforce declared type of `_value_`.
Does not enforce assigned tuple types for enum members (optional).
Does not evaluate literal types for enum member values (optional).
Does not evaluate literal types for auto values (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 78: Expected 1 errors
Line 85: Expected 1 errors
Line 75: Unexpected errors ['enums_member_values.py:75:0 Uninitialized attribute [13]: Attribute `_value_` is declared in class `Color3` to have type `Color3` but is never initialized.']
"""
output = """
enums_member_values.py:21:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:22:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:26:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal[1], typing_extensions.Literal[3]]` but got `typing.Any`.
enums_member_values.py:30:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal[1], typing_extensions.Literal[2], typing_extensions.Literal[3]]` but got `typing.Any`.
enums_member_values.py:54:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:68:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:75:0 Uninitialized attribute [13]: Attribute `_value_` is declared in class `Color3` to have type `Color3` but is never initialized.
enums_member_values.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `typing.Any`.
"""
43 changes: 43 additions & 0 deletions conformance/results/pyre/enums_members.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
conformant = "Partial"
notes = """
Does not reject use of annotation with enum member.
Does not treat callables as non-members.
Does not treat annotated attributes as non-members.
Does not honor `enum.nonmember` to define non-member attribute.
Does not honor `enum.member` as method decorator.
Does not properly handle aliased enum members.
Rejects use of `_ignore_`.
Does not support `_ignore_` mechanism (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 46: Expected 1 errors
Line 78: Expected 1 errors
Line 79: Expected 1 errors
Line 112: Expected 1 errors
Line 125: Expected 1 errors
Line 23: Unexpected errors ['enums_members.py:23:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.']
Line 24: Unexpected errors ['enums_members.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.']
Line 31: Unexpected errors ['enums_members.py:31:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.']
Line 32: Unexpected errors ['enums_members.py:32:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.']
Line 96: Unexpected errors ['enums_members.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[TrafficLight.YELLOW]` but got `typing_extensions.Literal[TrafficLight.AMBER]`.']
Line 113: Unexpected errors ['enums_members.py:113:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Example.c]` but got `member[typing.Callable(Example.c)[[Named(self, Example)], None]]`.']
Line 124: Unexpected errors ['enums_members.py:124:8 Revealed type [-1]: Revealed type for `enums_members.Example2._Example2__B` is `typing_extensions.Literal[Example2._Example2__B]` (final).']
Line 135: Unexpected errors ['enums_members.py:135:4 Inconsistent override [15]: `_ignore_` overrides attribute defined in `Enum` inconsistently. Type `Pet5` is not a subtype of the overridden attribute `typing.Union[typing.List[str], str]`.']
"""
output = """
enums_members.py:15:0 Uninitialized attribute [13]: Attribute `genus` is declared in class `Pet` to have type `Pet` but is never initialized.
enums_members.py:15:0 Uninitialized attribute [13]: Attribute `species` is declared in class `Pet` to have type `Pet` but is never initialized.
enums_members.py:23:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.
enums_members.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.
enums_members.py:31:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.
enums_members.py:32:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.
enums_members.py:80:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Pet4.species]` but got `str`.
enums_members.py:81:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Pet4.speak]` but got `typing.Callable(Pet4.speak)[[Named(self, Pet4)], None]`.
enums_members.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[TrafficLight.YELLOW]` but got `typing_extensions.Literal[TrafficLight.AMBER]`.
enums_members.py:113:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Example.c]` but got `member[typing.Callable(Example.c)[[Named(self, Example)], None]]`.
enums_members.py:124:8 Revealed type [-1]: Revealed type for `enums_members.Example2._Example2__B` is `typing_extensions.Literal[Example2._Example2__B]` (final).
enums_members.py:135:4 Inconsistent override [15]: `_ignore_` overrides attribute defined in `Enum` inconsistently. Type `Pet5` is not a subtype of the overridden attribute `typing.Union[typing.List[str], str]`.
enums_members.py:142:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Pet5`.
enums_members.py:143:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Pet5`.
"""
Loading

0 comments on commit 1e0d118

Please sign in to comment.