Skip to content

Commit eaa0872

Browse files
committed
Sort generated enum union by name for older versions of Python
1 parent df76db6 commit eaa0872

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mypy/checker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import itertools
44
import fnmatch
5+
import sys
56
from contextlib import contextmanager
67

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

0 commit comments

Comments
 (0)