-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Recognize stub pyi
Python files.
#2182
Recognize stub pyi
Python files.
#2182
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2182 +/- ##
=======================================
Coverage 92.60% 92.61%
=======================================
Files 94 94
Lines 10798 10812 +14
=======================================
+ Hits 9999 10013 +14
Misses 799 799
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
β¦__init__.pyi` file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great !
Only recognizing Could we get such cases fixed as well? |
Thank you @sighingnow. I think I would need a small working example to be sure I understand what the issue is. (venv310) $ tree not_working_ok/
not_working_ok/
βββ b
βββ c.pyi
1 directory, 1 file
(venv310) $ tree working_ok/
working_ok/
βββ b
βββ c.py
1 directory, 1 file
(venv310) $ cat working_ok/b/c.py
x = 42
(venv310) $ diff working_ok/b/c.py not_working_ok/b/c.pyi
(venv310) $
(venv310) $ pylint working_ok/
************* Module b.c
working_ok/b/c.py:1:0: C0114: Missing module docstring (missing-module-docstring)
working_ok/b/c.py:1:0: C0103: Constant name "x" doesn't conform to UPPER_CASE naming style (invalid-name)
working_ok/b/c.py:1:0: W0612: Unused variable 'x' (unused-variable)
-----------------------------------
Your code has been rated at 0.00/10
(venv310) $ pylint not_working_ok/
(venv310) $ <should be pylint messages here but there is not>
(venv310) $
(venv310) $ pylint not_working_ok/b/c.pyi
************* Module c
not_working_ok/b/c.pyi:1:0: C0114: Missing module docstring (missing-module-docstring)
not_working_ok/b/c.pyi:1:0: C0103: Constant name "x" doesn't conform to UPPER_CASE naming style (invalid-name)
not_working_ok/b/c.pyi:1:0: W0612: Unused variable 'x' (unused-variable) Note that while looking into this I see that https://github.com/pylint-dev/pylint/blob/main/pylint/lint/pylinter.py#L603 will need to be updated to include "pyi" also; that will fix my example above although I'm not 100% sure if it matches your use-case. |
@mbyrnepr2 Thanks for the case, that's exactly what I mean. I succeed by locally hacking Background: I use |
Perhaps you could open a pull-request with your working hack @sighingnow because I've tried this also and I don't see it working unfortunately. |
Hi @mbyrnepr2, I have opened the pull request: I misunderstood the case above and would like to give a minimal example of my problem (sorry for the incorrect comment above). I have (I use
From the case above you could see that $ pylint d.py
************* Module working_ok.d
d.py:1:0: C0114: Missing module docstring (missing-module-docstring)
d.py:2:20: E1101: Module 'working_ok.c' has no 'x' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00) After the hack in #2195, the error disappears: $ pylint d.py
************* Module working_ok.d
d.py:1:0: C0114: Missing module docstring (missing-module-docstring)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 0.00/10, +5.00) Note the hack in #2195 only resolves the problem above, and is not enough to support other cases (not very familiar with the internal of pylint). |
Further tweaks the case above (adding $ head -n 100 ./*
==> ./c.py <==
def _init():
import sys
setattr(sys.modules[__name__], 'x', 42)
_init()
==> ./c.pyi <==
x: int = 42
==> ./d.py <==
from . import c
print('x from c: ', c.x)
print('y from c: ', c.y)
==> ./__init__.py <== |
So, in other words if a module To be honest I didn't consider that dynamically assigned names would be in-scope for pylint-dev/pylint#4987. My understanding is that the scope was more narrow than that - i.e. to make it possible for Pylint to be able to lint .pyi files (previously they were ignored or not picked-up by astroid when searching for modules). @Pierre-Sassoulas @jacobtylerwalls what do you think? |
Agree that lint both |
Refs pylint-dev/pylint#4987
Type of Changes
Description
The result of this merge-request is to let Pylint analyse
__init__.pyi
files.Closes pylint-dev/pylint#4987