-
-
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
E0203(access-member-before-definition) wrongly detected in some cases #2315
Comments
When I downgrade to Pylint 1.9.2, this error isn't shown. |
Thanks for the report |
Reproducable in 2.1.1 |
In my setup, pylint warned about line 1 even though the offending line was on line 300. It took quite a bit of time before I realized the f-string was the problem. Side effect is that I cannot use the # pylint: disable comment on line 300. |
If it's helpful, E0118 (used-prior-global-declaration) can likewise be triggered with the f-string in the same manner. Just have a global that you use the global keyword on inside a function, and then print it out via an f-string. Same symptoms: it complains about it on line 1 of the script. Incidentally, this and the other error can be gotten around simply by using a local dummy variable before processing in the f-string: fp_num = 0
... do some stuff ...
def print_foo():
global fp_num
_fp_num = fp_num
print(f"fp_num is {_fp_num}") pylint 2.1.1 |
Same experience as jonapich, warning shows up on line 1 saying that I used a member prior to initialization on line 67. Actual issue was using |
Thanks for all the examples folks. |
It seems that pylint (v2.1.x) for python version 3.6 has some troubles when dealing with python3's f-string (the affected lines caused no troubles in python 3.7.x). The failure appears when accessing class variables set at __init__ method and trying to use the f-string feature, using those recently defined class variables. The problem is solved by using directly the passed variable via args instead of the class variable. References: pylint-dev/pylint#2315
Any update on getting this fixed...? |
Still actual for pylint 2.4.1 :( |
Another example unrelated to f-strings, pylint reports an error for an access before definition when immediately inside a test for a definition, e.g.
produces |
I'm closing this since the original issue reported is no longer reproducible on The issue reported by @carl3 does not trigger for: class TestClass(object):
def __init__(self, x):
if hasattr(self, "_text"):
print(self._text) If there are any other issue with Please let me know if there are still any problems with the originally reported issue and I'll gladly reopen! |
With a combination of Python 3.6 and f-strings pylint shows non-existing errors:
Steps to reproduce
__init__()
and then try to access an element of that dict inside an f-string, e.g.:Current behavior
Pylint shows an error:
Expected behavior
No error shown
pylint --version output
The text was updated successfully, but these errors were encountered: