Skip to content

Commit

Permalink
add xfail test for unsupported enum nonmember
Browse files Browse the repository at this point in the history
  • Loading branch information
terencehonles committed Jun 5, 2024
1 parent 8eb4218 commit dfcc0c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test-data/unit/check-python311.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
[case testMatchLiteralPatternEnumWithNonMember-xfail]
from enum import Enum, nonmember
from typing import NoReturn
def assert_never(x: NoReturn) -> None: ...

class int:
def __new__(cls, value: int): pass

class Medal(int, Enum):
prize: str = nonmember("nothing")

def __new__(cls, value: int, prize: str | None) -> Medal:
enum = int.__new__(cls, value)
enum._value_ = value
if prize is not None:
enum.prize = prize
return enum

gold = (1, 'cash prize')
silver = (2, 'sponsorship')
bronze = (3, 'nothing')

m: Medal

match m:
case Medal.gold:
reveal_type(m) # N: Revealed type is "Literal[__main__.Medal.gold]"
case Medal.silver:
reveal_type(m) # N: Revealed type is "Literal[__main__.Medal.silver]"
case Medal.bronze:
reveal_type(m) # N: Revealed type is "Literal[__main__.Medal.bronze]"
case _ as unreachable:
assert_never(unreachable)

[builtins fixtures/tuple.pyi]

[case testTryStarSimple]
try:
pass
Expand Down
3 changes: 3 additions & 0 deletions test-data/unit/lib-stub/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ class auto(IntFlag):
# It is python-3.11+ only:
class StrEnum(str, Enum):
def __new__(cls: Type[_T], value: str | _T) -> _T: ...


def nonmember(value: _T) -> _T: pass

0 comments on commit dfcc0c4

Please sign in to comment.