Skip to content

Commit 9a3308d

Browse files
author
Guido van Rossum
committed
Tweak import_priority; gives slightly fewer errors
1 parent a078583 commit 9a3308d

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
@@ -308,18 +308,17 @@ def default_lib_path(data_dir: str, pyversion: Tuple[int, int]) -> List[str]:
308308
PRI_MED = 10 # top-level "import X"
309309
PRI_LOW = 20 # either form inside a function
310310
PRI_INDIRECT = 30 # an indirect dependency
311-
PRI_MYPY = 40 # inside "if MYPY" or "if typing.TYPE_CHECKING"
312311
PRI_ALL = 99 # include all priorities
313312

314313

315314
def import_priority(imp: ImportBase, toplevel_priority: int) -> int:
316315
"""Compute import priority from an import node."""
317-
if imp.is_mypy_only:
318-
# Inside "if MYPY" or "if typing.TYPE_CHECKING"
319-
return PRI_MYPY
320316
if not imp.is_top_level:
321317
# Inside a function
322318
return PRI_LOW
319+
if imp.is_mypy_only:
320+
# Inside "if MYPY" or "if typing.TYPE_CHECKING"
321+
return max(PRI_MED, toplevel_priority)
323322
# A regular import; priority determined by argument.
324323
return toplevel_priority
325324

0 commit comments

Comments
 (0)