5050from pylint .lint .utils import (
5151 _is_relative_to ,
5252 augmented_sys_path ,
53+ realpath_transformer ,
5354 get_fatal_error_message ,
5455 prepare_crash_report ,
5556)
7475class GetAstProtocol (Protocol ):
7576 def __call__ (
7677 self , filepath : str , modname : str , data : str | None = None
77- ) -> nodes .Module : ...
78+ ) -> nodes .Module :
79+ ...
7880
7981
8082def _read_stdin () -> str :
@@ -308,9 +310,9 @@ def __init__(
308310 """Dictionary of possible but non-initialized reporters."""
309311
310312 # 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 )
314316 """Dictionary of registered and initialized checkers."""
315317 self ._dynamic_plugins : dict [str , ModuleType | ModuleNotFoundError | bool ] = {}
316318 """Set of loaded plugin names."""
@@ -671,6 +673,8 @@ def check(self, files_or_modules: Sequence[str]) -> None:
671673 for file_or_module in files_or_modules
672674 }
673675 )
676+ # Prefer package paths detected per module over user-defined PYTHONPATH additions
677+ extra_sys_paths = extra_packages_paths + realpath_transformer (self .config .pythonpath )
674678
675679 # TODO: Move the parallel invocation into step 3 of the checking process
676680 if not self .config .from_stdin and self .config .jobs > 1 :
@@ -679,13 +683,13 @@ def check(self, files_or_modules: Sequence[str]) -> None:
679683 self ,
680684 self .config .jobs ,
681685 self ._iterate_file_descrs (files_or_modules ),
682- extra_packages_paths ,
686+ extra_sys_paths ,
683687 )
684688 sys .path = original_sys_path
685689 return
686690
687691 # 1) Get all FileItems
688- with augmented_sys_path (extra_packages_paths ):
692+ with augmented_sys_path (extra_sys_paths ):
689693 if self .config .from_stdin :
690694 fileitems = self ._get_file_descr_from_stdin (files_or_modules [0 ])
691695 data : str | None = _read_stdin ()
@@ -694,7 +698,7 @@ def check(self, files_or_modules: Sequence[str]) -> None:
694698 data = None
695699
696700 # 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 ):
698702 with self ._astroid_module_checker () as check_astroid_module :
699703 # 2) Get the AST for each FileItem
700704 ast_per_fileitem = self ._get_asts (fileitems , data )
0 commit comments