Skip to content
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

PEP420 cyclic-import false positive #7959

Closed
alexey-pelykh opened this issue Dec 19, 2022 · 6 comments · Fixed by #8153
Closed

PEP420 cyclic-import false positive #7959

alexey-pelykh opened this issue Dec 19, 2022 · 6 comments · Fixed by #8153
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@alexey-pelykh
Copy link
Contributor

Bug description

https://github.com/alexey-pelykh/reproduce-pylint-pep420-cyclic-import-false-positive

pylint thinks that logging is the package name while due to implicit namespace, it's some.package.logging.

Configuration

[MASTER]
init-hook=
    from os.path import dirname, join
    from glob import glob
    from pylint.config import find_pylintrc
    from site import addsitedir
    site_packages_paths = glob(join(dirname(find_pylintrc()), '**', '*venv', '**', 'site-packages'), recursive=True)
    for site_packages_path in site_packages_paths: addsitedir(site_packages_path)

Command used

./venv/bin/pylint --recursive=y src
./venv/bin/pylint $(find src -name '*.py')

Pylint output

************* Module logging.wrapper.__init__
src/some/package/logging/wrapper/__init__.py:1:0: R0401: Cyclic import (logging -> logging.wrapper) (cyclic-import)

Expected behavior

No cyclic import detected

Pylint version

pylint 2.15.9
astroid 2.12.13
Python 3.11.0 (main, Oct 26 2022, 19:06:18) [Clang 14.0.0 (clang-1400.0.29.202)]

OS / Environment

No response

Additional dependencies

No response

@alexey-pelykh alexey-pelykh added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Dec 19, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 22, 2022
@alexey-pelykh
Copy link
Contributor Author

@Pierre-Sassoulas the reproduction repo linked did not work as reproduction for you?

@Pierre-Sassoulas
Copy link
Member

I did not have the time to try to reproduce, sorry about that. Multiple files reproducer and full repo reproducer takes longer to label and triage, but I usually reproduce when triaging and before labelling so the 'needs reproduction' label is never applied for most issue.

@alexey-pelykh
Copy link
Contributor Author

@Pierre-Sassoulas I've looked a bit deeper into the origins of the issue, it's more or less clear that with --recursive=y there's no way the implicit namespace will be detected since pylint no "sources root(s)" option to define from where to detect these implicit namespaces. That said, any insights on "source root(s)" concept in pylint? Discussions, PRs, etc?

@alexey-pelykh
Copy link
Contributor Author

A side note, that my original use case is with pre-commit where set of files is passed to pylint - which also disallows pylint to figure out the proper package name since no __init__.py in implicit namespaces, therefore concept of "source root(s)" pops up again.

@Pierre-Sassoulas
Copy link
Member

Thank you for looking into this !

That said, any insights on "source root(s)" concept in pylint? Discussions, PRs, etc?

That could be the huge merge request where the --recursive option was introduced (#5682) and possibly subsequent correcting MR, but I don't think we talked about the concept of source root here. Might be a hole in the design, but I think we mainly tried to implement the equivalent of the bash command "find all python file in this directory" that was used a lot in continuous integration (find . -iname "*.py" -exec pylint -E {} ;\ & co.).

@alexey-pelykh
Copy link
Contributor Author

Thanks, I'll look into the discussion! Yet from what I can see from the sources thus far, a PR is needed to introduce source root(s) concept to the configuration files to produce package names relative to those roots when the file is discovered under those roots while doing nothing to the package names if it's outside. The default list of source roots would be empty, not affecting the default behavior while fixing the issue for me :)

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Feb 9, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.0 milestone Feb 9, 2023
AdrianSosic added a commit to emdgroup/baybe that referenced this issue Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants