10000 Generalize reachability checks to support enums by Michael0x2a · Pull Request #7000 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Generalize reachability checks to support enums #7000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 8, 2019
Prev Previous commit
Next Next commit
Sort generated enum union by name for older versions of Python
  • Loading branch information
Michael0x2a committed Jun 16, 2019
commit eaa0872fc1a910d9f482231b3cf8957103fe2964
9 changes: 9 additions & 0 deletions mypy/checker.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import itertools
import fnmatch
import sys
from contextlib import contextmanager

from typing import (
Expand Down Expand Up @@ -4497,6 +4498,14 @@ class Color(Enum):
if not isinstance(symbol.node, Var):
continue
new_items.append(LiteralType(name, typ))
# SymbolTables are really just dicts, and dicts are guaranteed to preserve
# insertion order only starting with Python 3.7. So, we sort these for older
# versions of Python to help make tests deterministic.
#
# We could probably skip the sort for Python 3.6 since people probably run mypy
# only using CPython, but we might as well for the sake of full correctness.
if sys.version_info < (3, 7):
new_items.sort(key=lambda lit: lit.value)
return UnionType.make_simplified_union(new_items)
else:
return typ
Expand Down
0