Skip to content

Commit 78528f6

Browse files
committed
Move tests out of members/non-members section
1 parent 63fd2f4 commit 78528f6

File tree

1 file changed

+56
-34
lines changed
  • crates/ty_python_semantic/resources/mdtest

1 file changed

+56
-34
lines changed

crates/ty_python_semantic/resources/mdtest/enums.md

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,6 @@ class ColorStr(Enum):
5151
reveal_type(enum_members(ColorStr))
5252
```
5353

54-
### Generated `_name_` and `_value_` attributes
55-
56-
```py
57-
from enum import Enum
58-
from typing import Literal
59-
60-
class Color(Enum):
61-
RED = 1
62-
GREEN = 2
63-
BLUE = 3
64-
65-
reveal_type(Color.RED._name_) # revealed: Literal["RED"]
66-
reveal_type(Color.RED._value_) # revealed: Literal[1]
67-
```
68-
69-
### `name` attribute Literal unions
70-
71-
```py
72-
from enum import Enum
73-
from typing import Literal
74-
75-
class Color(Enum):
76-
RED = 1
77-
GREEN = 2
78-
BLUE = 3
79-
80-
def func1(red_or_blue: Literal[Color.RED, Color.BLUE]):
81-
reveal_type(red_or_blue.name) # revealed: Literal["RED", "BLUE"]
82-
83-
def func2(any_color: Color):
84-
# TODO: Literal["RED", "GREEN", "BLUE"]
85-
reveal_type(any_color.name) # revealed: Any
86-
```
87-
8854
### When deriving from `IntEnum`
8955

9056
```py
@@ -533,6 +499,62 @@ callable = Printer.STDERR
533499
callable("Another error!")
534500
```
535501

502+
## Special attributes on enum members
503+
504+
### `name` and `_name_`
505+
506+
```py
507+
from enum import Enum
508+
from typing import Literal
509+
510+
class Color(Enum):
511+
RED = 1
512+
GREEN = 2
513+
BLUE = 3
514+
515+
reveal_type(Color.RED._name_) # revealed: Literal["RED"]
516+
517+
def _(red_or_blue: Literal[Color.RED, Color.BLUE]):
518+
reveal_type(red_or_blue.name) # revealed: Literal["RED", "BLUE"]
519+
520+
def _(any_color: Color):
521+
# TODO: Literal["RED", "GREEN", "BLUE"]
522+
reveal_type(any_color.name) # revealed: Any
523+
```
524+
525+
### `value` and `_value_`
526+
527+
```toml
528+
[environment]
529+
python-version = "3.11"
530+
```
531+
532+
```py
533+
from enum import Enum, StrEnum
534+
from typing import Literal
535+
536+
class Color(Enum):
537+
RED = 1
538+
GREEN = 2
539+
BLUE = 3
540+
541+
reveal_type(Color.RED.value) # revealed: Literal[1]
542+
reveal_type(Color.RED._value_) # revealed: Literal[1]
543+
544+
reveal_type(Color.GREEN.value) # revealed: Literal[2]
545+
reveal_type(Color.GREEN._value_) # revealed: Literal[2]
546+
547+
class Answer(StrEnum):
548+
YES = "yes"
549+
NO = "no"
550+
551+
reveal_type(Answer.YES.value) # revealed: Literal["yes"]
552+
reveal_type(Answer.YES._value_) # revealed: Literal["yes"]
553+
554+
reveal_type(Answer.NO.value) # revealed: Literal["no"]
555+
reveal_type(Answer.NO._value_) # revealed: Literal["no"]
556+
```
557+
536558
## Properties of enum types
537559

538560
### Implicitly final

0 commit comments

Comments
 (0)