diff --git a/mypy/build.py b/mypy/build.py index 6513414dd298..4b5f7e1cf5dc 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2959,12 +2959,16 @@ def process_graph(graph: Graph, manager: BuildManager) -> None: # Order the SCC's nodes using a heuristic. # Note that ascc is a set, and scc is a list. scc = order_ascc(graph, ascc) - # If builtins is in the list, move it last. (This is a bit of - # a hack, but it's necessary because the builtins module is - # part of a small cycle involving at least {builtins, abc, - # typing}. Of these, builtins must be processed last or else - # some builtin objects will be incompletely processed.) + # Make the order of the SCC that includes 'builtins' and 'typing', + # among other things, predictable. Various things may break if + # the order changes. if 'builtins' in ascc: + scc = sorted(scc, reverse=True) + # If builtins is in the list, move it last. (This is a bit of + # a hack, but it's necessary because the builtins module is + # part of a small cycle involving at least {builtins, abc, + # typing}. Of these, builtins must be processed last or else + # some builtin objects will be incompletely processed.) scc.remove('builtins') scc.append('builtins') if manager.options.verbosity >= 2: