-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pylint treats package.module
same as package/module.py
in terms of search
#9915
Comments
Thank you for your work on this issue (PR included). An unification of the behavior of sys path discovery would be welcome. I've not been able to deeply immerse myself in the specifics of it so it's hard and frightening to review. The general feeling I have with this is that it's hard to test automatically and that we had a lot of problem last time it was modified. Someone need to be able to understand the problem in depth to fix it, and it look like that could be you 😄 I would start by checking the git blame on the failing tests to understand the context of the PR that introduced them (if they are accessible). If the code predates the migration out of Logilab, from bitbucket then to github, let's assume that it made sense between 2002 to 2014 but it might not make sense anymore. |
Thank you for the feedback. I will dig in over the next few days. I also going to spend some time doing some research at also something like mypy which also discovers and creates qualified module names. One thing which has not been clear from pylint documentation is what the qualified module name rules are and how import module discovery works. So it is at least worth documenting to begin with. May be I have missed it on the page. I will document that if it doesn't exist. |
I think you are right that changing behavior is going to be extremely messy and disruptive and break existing code based on whatever behaviors that were observed. I do see Here is one proposal. How about we keep existing behavior as is and introduce a new flag like |
An option to be able to do that sounds reasonable. But why push user away from file/dir ? It's awfully conveniant because of the operating systeme autocomplete. |
package.module
same as package/module.py
package.module
same as package/module.py
in terms of search
Because with the So if you call your module with python as:
In
except that we could say the presence of With the -s option when used with scripts or directories, the autocomplete of the OS will still be available. By the way, one more place where the current behavior is confusing is how Another case where it confusing |
I think your changes make sense. Making What we probably need is a clear guide (that we could include in the changelog) which clearly describes how somebody could currently invoke Does that sound like a good step forward to you and Pierre? |
Thank you for the feedback! I will work on the -m for modules for a single module first and send a PR including doc changes and tests. May be a couple of weeks is what it will take. Once I get feedback, I can iterate on further. |
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 ofsys.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 callpython3.12 -m pylint package.module
orpython3.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:
contents of a.py:
contents of mypackage/mymodule.py
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.
Command used
Pylint output
Expected behavior
Pylint version
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
The text was updated successfully, but these errors were encountered: