Description
Bug description
As per sys.path initialization docs https://docs.python.org/3/library/sys_path_init.html, the sys.path entry depends on whether python is passed an input script named package/module.py
or whether it is invoked through -m package.module
option. In the former case, package
gets added to the start of sys.path
and, in the latter case, the current directory gets added. pylint doesn't have show this distinction. The search behavior is the same whether we call python3.12 -m pylint package.module
or python3.12 -m pylint package/module.py
although the module name and search path will depend on separate factors. Pylint ends up walking up the directory structure and adds the first directory that doesn't have __init__.py
Say I have the following:
.
├── a.py
└── mypackage
├── __init__.py
└── mymodule.py
contents of a.py:
def myfunc():
print("Hello World")
contents of mypackage/mymodule.py
import a
a.myfunc()
See pylint output below.
I attempted to fix this in #9910 but have run into regression failures as per the current behavior expected by those regressions. I would love to know thoughts on how we should proceed.
### Configuration
```ini
None
Command used
See above and below
Pylint output
pylinttest akamat10$ python3.12 -m pylint -d C0114 mypackage/mymodule.py
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
pylinttest akamat10$ python3.12 -m pylint -d C0114 mypackage.mymodule
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Expected behavior
pylinttest akamat10$ python3.12 -m pylint -d C0114 mypackage/mymodule.py
************* Module mypackage.mymodule
mypackage/mymodule.py:1:0: E0401: Unable to import 'a' (import-error)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Pylint version
pylint 3.2.7
astroid 3.2.4
Python 3.12.3 (v3.12.3:f6650f9ad7, Apr 9 2024, 08:18:47) [Clang 13.0.0 (clang-1300.0.29.30)]
OS / Environment
Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:19:22 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8112 arm64
Additional dependencies
No response