diff options
| author | Saugat Pachhai (सौगात) <suagatchhetri@outlook.com> | 2022-09-21 17:53:50 +0545 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-10-10 13:17:55 +0200 |
| commit | b05a51f77e399fd7849f825a545e375ebde02fc6 (patch) | |
| tree | f573f190d6bee79eb5953430c4d00f390548530d /.github | |
| parent | eafc0ff093fdd55d892d023887984617742f4daf (diff) | |
| download | astroid-git-b05a51f77e399fd7849f825a545e375ebde02fc6.tar.gz | |
improve is_namespace check
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 https://github.com/PyCQA/pylint/issues/7488.
Diffstat (limited to '.github')
0 files changed, 0 insertions, 0 deletions
