50
50
from pylint .lint .utils import (
51
51
_is_relative_to ,
52
52
augmented_sys_path ,
53
+ realpath_transformer ,
53
54
get_fatal_error_message ,
54
55
prepare_crash_report ,
55
56
)
74
75
class GetAstProtocol (Protocol ):
75
76
def __call__ (
76
77
self , filepath : str , modname : str , data : str | None = None
77
- ) -> nodes .Module : ...
78
+ ) -> nodes .Module :
79
+ ...
78
80
79
81
80
82
def _read_stdin () -> str :
@@ -308,9 +310,9 @@ def __init__(
308
310
"""Dictionary of possible but non-initialized reporters."""
309
311
310
312
# Attributes for checkers and plugins
311
- self ._checkers : defaultdict [str , list [ checkers . BaseChecker ]] = (
312
- collections . defaultdict ( list )
313
- )
313
+ self ._checkers : defaultdict [
314
+ str , list [ checkers . BaseChecker ]
315
+ ] = collections . defaultdict ( list )
314
316
"""Dictionary of registered and initialized checkers."""
315
317
self ._dynamic_plugins : dict [str , ModuleType | ModuleNotFoundError | bool ] = {}
316
318
"""Set of loaded plugin names."""
@@ -671,6 +673,8 @@ def check(self, files_or_modules: Sequence[str]) -> None:
671
673
for file_or_module in files_or_modules
672
674
}
673
675
)
676
+ # Prefer package paths detected per module over user-defined PYTHONPATH additions
677
+ extra_sys_paths = extra_packages_paths + realpath_transformer (self .config .pythonpath )
674
678
675
679
# TODO: Move the parallel invocation into step 3 of the checking process
676
680
if not self .config .from_stdin and self .config .jobs > 1 :
@@ -679,13 +683,13 @@ def check(self, files_or_modules: Sequence[str]) -> None:
679
683
self ,
680
684
self .config .jobs ,
681
685
self ._iterate_file_descrs (files_or_modules ),
682
- extra_packages_paths ,
686
+ extra_sys_paths ,
683
687
)
684
688
sys .path = original_sys_path
685
689
return
686
690
687
691
# 1) Get all FileItems
688
- with augmented_sys_path (extra_packages_paths ):
692
+ with augmented_sys_path (extra_sys_paths ):
689
693
if self .config .from_stdin :
690
694
fileitems = self ._get_file_descr_from_stdin (files_or_modules [0 ])
691
695
data : str | None = _read_stdin ()
@@ -694,7 +698,7 @@ def check(self, files_or_modules: Sequence[str]) -> None:
694
698
data = None
695
699
696
700
# The contextmanager also opens all checkers and sets up the PyLinter class
697
- with augmented_sys_path (extra_packages_paths ):
701
+ with augmented_sys_path (extra_sys_paths ):
698
702
with self ._astroid_module_checker () as check_astroid_module :
699
703
# 2) Get the AST for each FileItem
700
704
ast_per_fileitem = self ._get_asts (fileitems , data )
0 commit comments