Skip to content

Commit 94ac31a

Browse files
author
Guido van Rossum
committed
Tweak import_priority; gives slightly fewer errors
1 parent 7119f75 commit 94ac31a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

mypy/build.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,17 @@ def default_lib_path(data_dir: str, pyversion: Tuple[int, int]) -> List[str]:
305305
PRI_MED = 10 # top-level "import X"
306306
PRI_LOW = 20 # either form inside a function
307307
PRI_INDIRECT = 30 # an indirect dependency
308-
PRI_MYPY = 40 # inside "if MYPY" or "if typing.TYPE_CHECKING"
309308
PRI_ALL = 99 # include all priorities
310309

311310

312311
def import_priority(imp: ImportBase, toplevel_priority: int) -> int:
313312
"""Compute import priority from an import node."""
314-
if imp.is_mypy_only:
315-
# Inside "if MYPY" or "if typing.TYPE_CHECKING"
316-
return PRI_MYPY
317313
if not imp.is_top_level:
318314
# Inside a function
319315
return PRI_LOW
316+
if imp.is_mypy_only:
317+
# Inside "if MYPY" or "if typing.TYPE_CHECKING"
318+
return max(PRI_MED, toplevel_priority)
320319
# A regular import; priority determined by argument.
321320
return toplevel_priority
322321

0 commit comments

Comments
 (0)