| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3247,10 +3247,26 @@ def enum_members(self) -> list[str]: | |||
| 3247 | 3247 | name | |
| 3248 | 3248 | for name, sym in self.names.items() | |
| 3249 | 3249 | if ( | |
| 3250 | - isinstance(sym.node, Var) | ||
| 3251 | - and name not in EXCLUDED_ENUM_ATTRIBUTES | ||
| 3252 | - and not name.startswith("__") | ||
| 3253 | - and sym.node.has_explicit_value | ||
| 3250 | + ( | ||
| 3251 | + isinstance(sym.node, Var) | ||
| 3252 | + and name not in EXCLUDED_ENUM_ATTRIBUTES | ||
| 3253 | + and not name.startswith("__") | ||
| 3254 | + and sym.node.has_explicit_value | ||
| 3255 | + and not ( | ||
| 3256 | + isinstance( | ||
| 3257 | + typ := mypy.types.get_proper_type(sym.node.type), mypy.types.Instance | ||
| 3258 | + ) | ||
| 3259 | + and typ.type.fullname == "enum.nonmember" | ||
| 3260 | + ) | ||
| 3261 | + ) | ||
| 3262 | + or ( | ||
| 3263 | + isinstance(sym.node, Decorator) | ||
| 3264 | + and any( | ||
| 3265 | + dec.fullname == "enum.member" | ||
| 3266 | + for dec in sym.node.decorators | ||
| 3267 | + if isinstance(dec, RefExpr) | ||
| 3268 | + ) | ||
| 3269 | + ) | ||
| 3254 | 3270 | ) | |
| 3255 | 3271 | ] | |
| 3256 | 3272 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -955,7 +955,7 @@ class Status(Enum): | |||
| 955 | 955 | FAILURE = 2 | |
| 956 | 956 | UNKNOWN = 3 | |
| 957 | 957 | ||
| 958 | - ...and if we call `try_expanding_enum_to_union(Union[Color, Status], 'module.Color')`, | ||
| 958 | + ...and if we call `try_expanding_sum_type_to_union(Union[Color, Status], 'module.Color')`, | ||
| 959 | 959 | this function will return Literal[Color.RED, Color.BLUE, Color.YELLOW, Status]. | |
| 960 | 960 | """ | |
| 961 | 961 | typ = get_proper_type(typ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1933,6 +1933,18 @@ class D(C): # E: Cannot extend enum with existing members: "C" \ | |||
| 1933 | 1933 | x: int # E: Cannot assign to final name "x" | |
| 1934 | 1934 | [builtins fixtures/bool.pyi] | |
| 1935 | 1935 | ||
| 1936 | + [case testEnumNotFinalWithMethodsAndUninitializedValuesStubMember] | ||
| 1937 | + # flags: --python-version 3.11 | ||
| 1938 | + # This was added in 3.11 | ||
| 1939 | + import lib | ||
| 1940 | + | ||
| 1941 | + [file lib.pyi] | ||
| 1942 | + from enum import Enum, member | ||
| 1943 | + class A(Enum): | ||
| 1944 | + @member | ||
| 1945 | + def x(self) -> None: ... | ||
| 1946 | + [builtins fixtures/bool.pyi] | ||
| 1947 | + | ||
| 1936 | 1948 | [case testEnumLiteralValues] | |
| 1937 | 1949 | from enum import Enum | |
| 1938 | 1950 | ||
@@ -2325,6 +2337,28 @@ def some_a(a: A): | |||
| 2325 | 2337 | [builtins fixtures/dict.pyi] | |
| 2326 | 2338 | ||
| 2327 | 2339 | ||
| 2340 | + [case testEnumMemberAndNonMemberSupport] | ||
| 2341 | + # flags: --python-version 3.11 --warn-unreachable | ||
| 2342 | + # This was added in 3.11 | ||
| 2343 | + from enum import Enum, member, nonmember | ||
| 2344 | + | ||
| 2345 | + class A(Enum): | ||
| 2346 | + x = 1 | ||
| 2347 | + y = member(2) | ||
| 2348 | + z = nonmember(3) | ||
| 2349 | + | ||
| 2350 | + def some_a(a: A): | ||
| 2351 | + if a is not A.x and a is not A.z: | ||
| 2352 | + reveal_type(a) # N: Revealed type is "Literal[__main__.A.y]" | ||
| 2353 | + if a is not A.y and a is not A.z: | ||
| 2354 | + reveal_type(a) # N: Revealed type is "Literal[__main__.A.x]" | ||
| 2355 | + if a is not A.x: | ||
| 2356 | + reveal_type(a) # N: Revealed type is "Literal[__main__.A.y]" | ||
| 2357 | + if a is not A.y: | ||
| 2358 | + reveal_type(a) # N: Revealed type is "Literal[__main__.A.x]" | ||
| 2359 | + [builtins fixtures/dict.pyi] | ||
| 2360 | + | ||
| 2361 | + | ||
| 2328 | 2362 | [case testErrorOnAnnotatedMember] | |
| 2329 | 2363 | from enum import Enum | |
| 2330 | 2364 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments