From 367b29d4aac16fc7493abffe2df0d8f477c23923 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Wed, 23 Mar 2022 13:33:38 +0000 Subject: [PATCH] Make order of processing the builtins SCC predictable (#12431) Various things can go wrong if the order of modules in the builtins SCC that also includes typing, _typeshed and others is adjusted. Hopefully fixes #12422. May also fix #12421. --- mypy/build.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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: