Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion conformance/results/mypy/enums_behaviors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ conformant = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39: error: Cannot extend enum with existing members: "Shape" [misc]
enums_behaviors.py:28: error: Expression is of type "Color", not "Literal[Color.RED]" [assert-type]
enums_behaviors.py:32: error: Expression is of type "Color", not "Literal[Color.BLUE]" [assert-type]
enums_behaviors.py:44: error: Cannot extend enum with existing members: "Shape" [misc]
"""
conformance_automated = "Pass"
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.17.0"
test_duration = 2.7
test_duration = 1.9
4 changes: 3 additions & 1 deletion conformance/results/pyre/enums_behaviors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39:0 Invalid inheritance [39]: Cannot inherit from final enum `Shape`. Enums with defined members cannot be extended.
enums_behaviors.py:28:0 Assert type [70]: Expected `typing_extensions.Literal[Color.RED]` but got `Color`.
enums_behaviors.py:32:0 Assert type [70]: Expected `typing_extensions.Literal[Color.BLUE]` but got `Color`.
enums_behaviors.py:44:0 Invalid inheritance [39]: Cannot inherit from final enum `Shape`. Enums with defined members cannot be extended.
"""
4 changes: 2 additions & 2 deletions conformance/results/pyre/qualifiers_final_decorator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ qualifiers_final_decorator.py:126:0 Invalid inheritance [39]: `final` cannot be
"""
conformance_automated = "Fail"
errors_diff = """
Lines 80, 89: Expected error (tag 'Derived3')
Lines 94, 102: Expected error (tag 'Derived4')
Lines 80, 81, 89: Expected error (tag 'Derived3')
Lines 94, 95, 102: Expected error (tag 'Derived4')
Line 51: Unexpected errors ['qualifiers_final_decorator.py:51:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).']
"""
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.25"
test_duration = 3.9
test_duration = 7.4
4 changes: 3 additions & 1 deletion conformance/results/pyright/enums_behaviors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ conformant = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39:21 - error: Enum class "Shape" is final and cannot be subclassed (reportGeneralTypeIssues)
enums_behaviors.py:28:13 - error: "assert_type" mismatch: expected "Literal[Color.RED]" but received "Color" (reportAssertTypeFailure)
enums_behaviors.py:32:13 - error: "assert_type" mismatch: expected "Literal[Color.BLUE]" but received "Color" (reportAssertTypeFailure)
enums_behaviors.py:44:21 - error: Enum class "Shape" is final and cannot be subclassed (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
2 changes: 1 addition & 1 deletion conformance/results/pyright/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyright 1.1.403"
test_duration = 5.6
test_duration = 1.4
6 changes: 3 additions & 3 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ <h3>Python Type System Conformance Test Results</h3>
<div class="table_container"><table><tbody>
<tr><th class="col1">&nbsp;</th>
<th class='tc-header'><div class='tc-name'>mypy 1.17.0</div>
<div class='tc-time'>2.7sec</div>
<div class='tc-time'>1.9sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyright 1.1.403</div>
<div class='tc-time'>5.6sec</div>
<div class='tc-time'>1.4sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyre 0.9.25</div>
<div class='tc-time'>3.9sec</div>
<div class='tc-time'>7.4sec</div>
</th>
</tr>
<tr><th class="column" colspan="4">
Expand Down
11 changes: 8 additions & 3 deletions conformance/tests/enums_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Specification: https://typing.readthedocs.io/en/latest/spec/enums.html#enum-definition

from enum import Enum
from typing import assert_type
from typing import assert_type, Literal

# > Enum classes are iterable and indexable, and they can be called with a
# > value to look up the enum member with that value. Type checkers should
Expand All @@ -23,8 +23,13 @@ class Color(Enum):
# > constructor. Instead, the call performs a value-based lookup of an
# > enum member.

assert_type(Color["RED"], Color) # 'Literal[Color.RED]' is also acceptable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

felt odd to assert_type here and say that another type is also acceptable. I tried to put both versions down, so that type checkers have discretion on which one to implement w/o the test failing.

I assume that if a checker emits an error on both lines the test will fail - could the maintainers please confirm this assumption?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right; this is documented in the "Test case syntax" section in conformance/README.

assert_type(Color(3), Color) # 'Literal[Color.BLUE]' is also acceptable
# 'Literal[Color.RED]' and 'Color' are both acceptable
assert_type(Color["RED"], Color) # E[red]
assert_type(Color["RED"], Literal[Color.RED]) # E[red]

# 'Literal[Color.BLUE]' and 'Color' are both acceptable
assert_type(Color(3), Color) # E[blue]
assert_type(Color(3), Literal[Color.BLUE]) # E[blue]


# > An Enum class with one or more defined members cannot be subclassed.
Expand Down
6 changes: 3 additions & 3 deletions conformance/tests/qualifiers_final_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def method3() -> None: # E[method3]
pass

@overload # E[method4]
def method4(self, x: int) -> int:
def method4(self, x: int) -> int: # E[method4]
Copy link
Contributor Author

@yangdanny97 yangdanny97 Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pyrefly emits diagnostics on the line of the def, not the line with the @overload

This is similar to what I did in #1980

...

@overload
Expand All @@ -78,7 +78,7 @@ def method4(self, x: int | str) -> int | str: # E[method4]

class Derived3(Base3):
@overload # E[Derived3]
def method(self, x: int) -> int:
def method(self, x: int) -> int: # E[Derived3]
...

@overload # E[Derived3-2]
Expand All @@ -92,7 +92,7 @@ def method(self, x: int | str) -> int | str: # E[Derived3]

class Derived4(Base4):
@overload # E[Derived4]
def method(self, x: int) -> int:
def method(self, x: int) -> int: # E[Derived4]
...

@overload
Expand Down