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

[feature] Being able to use stub pyi files in pylint #4987

Closed
daltairwalter opened this issue Sep 9, 2021 · 15 comments · Fixed by pylint-dev/astroid#2182
Closed

[feature] Being able to use stub pyi files in pylint #4987

daltairwalter opened this issue Sep 9, 2021 · 15 comments · Fixed by pylint-dev/astroid#2182
Labels
Enhancement ✨ Improvement to a component High priority Issue with more than 10 reactions
Milestone

Comments

@daltairwalter
Copy link

daltairwalter commented Sep 9, 2021

Bug description

I made some pyi files from pyd's using a stubgen program and I would like to use these pyi files for pylint.

I tried making some test cases with *.pyi files and they seem to be entirely ignored by pylint. I searched for other issues related to pyi/stubs and there seemed to be a few issues, but none of them said these files were just flat out unused - so I am wondering if something else is going on.

This seems to work if I delete the *.pyd files and rename the *.pyi files to *.py. Is this necessary?

When I import and use these files directly, there error messages are reasonably ignorable things like:

UseLocation.py:3:7: I1101: Module 'pylintimportstar.RealLocation' has no 'RealClass' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)

Unfortunately, when used through an import statement:
from pylintimportstar.RealLocation import *
The messages are all errors:

UseLocation.py:3:7: E1101: Module 'pylintimportstar' has no 'ReferenceLocation' member (no-member)

Command used

C:\programs\anaconda3\Scripts\pylint.exe C:\test\pylintimportstar2\pylintimportstar

Pylint output

************* Module ReferenceLocation
ReferenceLocation.py:1:0: C0304: Final newline missing (missing-final-newline)
ReferenceLocation.py:1:0: C0103: Module name "ReferenceLocation" doesn't conform to snake_case naming style (invalid-name)
ReferenceLocation.py:1:0: C0114: Missing module docstring (missing-module-docstring)
ReferenceLocation.py:1:0: W0401: Wildcard import pylintimportstar.RealLocation (wildcard-import)
************* Module UseLocation
UseLocation.py:4:0: C0304: Final newline missing (missing-final-newline)
UseLocation.py:1:0: C0103: Module name "UseLocation" doesn't conform to snake_case naming style (invalid-name)
UseLocation.py:1:0: C0114: Missing module docstring (missing-module-docstring)
UseLocation.py:3:7: E1101: Module 'pylintimportstar.ReferenceLocation' has no 'RealClass' member (no-member)

Expected behavior

The error E1101 is not expected.

Pylint version

pylint 2.10.2
astroid 2.7.3
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Maintainer note: this was a duplicate of #2873 which has 11 👍 already so this is higher priority than it appear just by sorting by thumbsup.

@daltairwalter daltairwalter added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 9, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Question and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 9, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Nov 9, 2021
@Pierre-Sassoulas Pierre-Sassoulas changed the title stub pyi files don't appear to do anything [feature] Being able to use stub pyi files in pylint Nov 9, 2021
@theCapypara
Copy link

theCapypara commented May 25, 2022

Is there any progress/update on this? This seems like a pretty common usecase nowadays and I was surprised to find out, it's not supported.

Or is there at least a workaround? I couldn't find a way to have pylint just ignore imports and missing members from certain packages.

@Pierre-Sassoulas Pierre-Sassoulas added the High priority Issue with more than 10 reactions label May 25, 2022
@Pierre-Sassoulas Pierre-Sassoulas pinned this issue May 25, 2022
@Pierre-Sassoulas
Copy link
Member

I don't think anyone worked on it yet. I pinned the issue. Regarding the workaround some options from the typechecker could help you, in particular generated-members.

@butla
Copy link

butla commented Jan 13, 2023

@Pierre-Sassoulas thanks for the tip with generated-members, it helped in my case.
Well, it didn't silence the no-name-in-module I had when doing from <module> import <name>. But when I changed the import to import <module> and started using qualified names in code (<module>.<name>), there were no errors.

@belm0
Copy link
Contributor

belm0 commented Mar 17, 2023

generated-members is a poor workaround-- as mentioned it doesn't affect imports

@zs-dima
Copy link

zs-dima commented May 9, 2023

Wow, 2 years and this issue still there
It is specially critical for gRPC generated pyi files

@Pierre-Sassoulas
Copy link
Member

@zs-dima do you want to work on it ?

@zs-dima
Copy link

zs-dima commented May 9, 2023

@Pierre-Sassoulas Sounds tempting, but there are more critical gRPC things that need fixing.

@jacobtylerwalls jacobtylerwalls removed Documentation 📗 Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed labels May 15, 2023
@jacobtylerwalls jacobtylerwalls unpinned this issue May 15, 2023
mbyrnepr2 added a commit to pylint-dev/astroid that referenced this issue May 16, 2023
Recognize stub ``pyi`` Python files.

Refs pylint-dev/pylint#4987

Co-authored-by: Jacob Walls <[email protected]>
@simoncpu
Copy link

Greetings! I'm a time traveler from the year 2023, and I'm experiencing this problem as well.

@Pierre-Sassoulas
Copy link
Member

It's fixed only on the main branch and not yet released, what version are you using ?

@idkw
Copy link

idkw commented Sep 25, 2023

Could this change be backported to the 2.x branch ? Version 3.x is not yet released and this missing feature is a real blocker on the 2.x

@Pierre-Sassoulas
Copy link
Member

There's an alpha of pylint 3.0.0 that is really stable if you want the fix right now (https://pypi.org/project/pylint/3.0.0a7/) and we're going to release 3.0.0b0 in days, and the actual 3.0.0 in a week for python 3.12 release.

@davetapley
Copy link

I'm seeing this with pylint == 3.0.2 and orjson==3.8.6.

ng/asset/meta.py:6:0: E0611: No name 'JSONDecodeError' in module 'orjson' (no-name-in-module)
ng/asset/meta.py:6:0: E0611: No name 'loads' in module 'orjson' (no-name-in-module)

But: https://github.com/ijl/orjson/blob/3.9.6/pysrc/orjson/__init__.pyi#L11-L13

and I verified that file is in my site-packages, any ideas? 🤔

@jimmyzzxhlh
Copy link

I'm running into this issue for protobuf and pylint 3.0.2 is still not working, e.g.
E0611: No name 'FloatValue' in module 'google.protobuf.wrappers_pb2' (no-name-in-module)

Can we check if this is actually fixed?

@Pierre-Sassoulas
Copy link
Member

Hello, thank you for reporting a problem, but please open a new issue, or your feedback is going to get lost in this closed issue.

@davetapley
Copy link

davetapley commented Feb 7, 2024

Missed this, but looks promising:

I still feel like we need something to pass to [tool.pylint.typecheck] though, so it can know that the root is, something like PyRight's stubPath?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component High priority Issue with more than 10 reactions
Projects
None yet
Development

Successfully merging a pull request may close this issue.