← Back to index
enums_member_names.py
TP: 0
FP: 0
FN: 0
Optional: 0 / 4
2Tests that the type checker handles the `_name_` and `name` attributes correctly.
5# Specification: https://typing.readthedocs.io/en/latest/spec/enums.html#member-names
8from typing import Literal, assert_type
10# > All enum member objects have an attribute _name_ that contains the member’s
11# > name. They also have a property name that returns the same name. Type
12# > checkers may infer a literal type for the name of a member
21assert_type(Color.RED._name_, Literal["RED"]) # E?
22assert_type(Color.RED.name, Literal["RED"]) # E?
25def func1(red_or_blue: Literal[Color.RED, Color.BLUE]):
26 assert_type(red_or_blue.name, Literal["RED", "BLUE"]) # E?
29def func2(any_color: Color):
30 assert_type(any_color.name, Literal["RED", "BLUE", "GREEN"]) # E?