-
-
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 crashes when importing submodule from a module of same name as the current file #7488
Labels
Astroid
Related to astroid
Cannot reproduce 🤷
Crash 💥
A bug that makes pylint crash
Downstream Bug 🪲
The problem happens in a lib depending on pylint, not pylint
Comments
skshetry
added
the
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
label
Sep 19, 2022
skshetry
added a commit
to iterative/dvc
that referenced
this issue
Sep 19, 2022
See pylint-dev/pylint#7488. Pylint is failing on our codebase.
skshetry
added a commit
to iterative/dvc
that referenced
this issue
Sep 19, 2022
See pylint-dev/pylint#7488. Pylint is failing on our codebase.
Pierre-Sassoulas
added
Astroid
Related to astroid
Crash 💥
A bug that makes pylint crash
Needs investigation 🔬
A bug or crash where it's not immediately obvious what is happenning
and removed
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
labels
Sep 19, 2022
mbyrnepr2
added
Needs reproduction 🔍
Need a way to reproduce it locally on a maintainer's machine
Cannot reproduce 🤷
labels
Sep 19, 2022
I've tried reproducing with the reported Pylint/astroid/Python versions but no luck. |
Looking closely, it seems like this is happening when [tool.pylint.master]
load-plugins = ["pylint_pytest"] |
Pierre-Sassoulas
added
Downstream Bug 🪲
The problem happens in a lib depending on pylint, not pylint
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
Sep 20, 2022
skshetry
added a commit
to skshetry/astroid
that referenced
this issue
Sep 21, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From pylint-dev#1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. But if you have imported it as `celery.result`, `sys.modules["celery"].__spec__` is going to be `None`, and hence the function will return True, and but below where we try to load get `submodule_path`/`__path__` for `celery.result` will fail as it is not a package. See https://github.com/PyCQA/astroid/blob/056d8e5fab7a167f73115d524ab92170b3ed5f9f/astroid/interpreter/_import/spec.py#L205-L207 --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `find_spec("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. I still think there's a bug for the `ExplicitNamespacePackageFinder.find_module` for namespace packages, since `modname` might be `namespace.package.module` but since `is_namespace` package goes through components, the successive `sys.modules[modname].__path__` may raise error, since modname could be not a package in a namespaced package. But I am not quite sure about that. Fixes pylint-dev/pylint#7488.
2 tasks
skshetry
added a commit
to skshetry/astroid
that referenced
this issue
Sep 21, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From pylint-dev#1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. But if you have imported it as `celery.result`, `sys.modules["celery"].__spec__` is going to be `None`, and hence the function will return True, and but below where we try to load get `submodule_path`/`__path__` for `celery.result` will fail as it is not a package. See https://github.com/PyCQA/astroid/blob/056d8e5fab7a167f73115d524ab92170b3ed5f9f/astroid/interpreter/_import/spec.py#L205-L207 --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `find_spec("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. Fixes pylint-dev/pylint#7488.
skshetry
added a commit
to skshetry/astroid
that referenced
this issue
Sep 21, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From pylint-dev#1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. `celery` is recreating module to make it lazily load. See https://github.com/celery/celery/blob/34533ab44d2a6492004bc3df44dc04ad5c6611e7/celery/__init__.py#L150. This module does not have `__spec__` set. Reading through Python's docs, it seems that `__spec__` can be set to None, so it seems like it's not a thing that we can depend upon for namespace checks. See https://docs.python.org/3/reference/import.html#spec__. --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `importlib.util._find_spec_from_path("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. Fixes pylint-dev/pylint#7488.
DanielNoord
pushed a commit
to pylint-dev/astroid
that referenced
this issue
Sep 23, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From #1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. `celery` is recreating module to make it lazily load. See https://github.com/celery/celery/blob/34533ab44d2a6492004bc3df44dc04ad5c6611e7/celery/__init__.py#L150. This module does not have `__spec__` set. Reading through Python's docs, it seems that `__spec__` can be set to None, so it seems like it's not a thing that we can depend upon for namespace checks. See https://docs.python.org/3/reference/import.html#spec__. --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `importlib.util._find_spec_from_path("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. Fixes pylint-dev/pylint#7488.
Pierre-Sassoulas
pushed a commit
to pylint-dev/astroid
that referenced
this issue
Oct 10, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From #1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. `celery` is recreating module to make it lazily load. See https://github.com/celery/celery/blob/34533ab44d2a6492004bc3df44dc04ad5c6611e7/celery/__init__.py#L150. This module does not have `__spec__` set. Reading through Python's docs, it seems that `__spec__` can be set to None, so it seems like it's not a thing that we can depend upon for namespace checks. See https://docs.python.org/3/reference/import.html#spec__. --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `importlib.util._find_spec_from_path("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. Fixes pylint-dev/pylint#7488.
Pierre-Sassoulas
pushed a commit
to pylint-dev/astroid
that referenced
this issue
Oct 10, 2022
See https://stackoverflow.com/a/42962529. Let's take the following contents as an example: ```python import celery.result ``` From #1777, astroid started to use `processed_components` for namespace check. In the above case, the `modname` is `celery.result`, it first checks for `celery` and then `celery.result`. Before that PR, it'd always check for `celery.result`. `celery` is recreating module to make it lazily load. See https://github.com/celery/celery/blob/34533ab44d2a6492004bc3df44dc04ad5c6611e7/celery/__init__.py#L150. This module does not have `__spec__` set. Reading through Python's docs, it seems that `__spec__` can be set to None, so it seems like it's not a thing that we can depend upon for namespace checks. See https://docs.python.org/3/reference/import.html#spec__. --- The `celery.result` gets imported for me when pylint-pytest plugin tries to load fixtures, but this could happen anytime if any plugin imports packages. In that case, `importlib.util._find_spec_from_path("celery")` will raise ValueError since it's already in `sys.modules` and does not have a spec. Fixes pylint-dev/pylint#7488.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Astroid
Related to astroid
Cannot reproduce 🤷
Crash 💥
A bug that makes pylint crash
Downstream Bug 🪲
The problem happens in a lib depending on pylint, not pylint
Bug description
Let's say you have the following directory structure:
and
celery.py
has a contentimport celery.result
.You can generate the above result using:
This crashes pylint. See below for the traceback. Note that
astroid==2.12.9
works, it's probably a regression in2.12.10
Configuration
No response
Command used
`pylint package`
Pylint output
Expected behavior
Pylint does not crashes.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: