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

Undefined variable '__class__' (undefined-variable) seems back with Python 3.8 #3090

Closed
adelton opened this issue Sep 5, 2019 · 4 comments
Closed
Labels

Comments

@adelton
Copy link

adelton commented Sep 5, 2019

Steps to reproduce

  1. Have test.py with content
class Class:
    def method(self):
        print(__class__)
Class().method()
  1. Run pylint-3 --disable=R --disable=C test.py

Current behavior

************* Module test
/test.py:3:14: E0602: Undefined variable '__class__' (undefined-variable)

--------------------------------------------------------------------
Your code has been rated at -2.50/10 (previous run: -6.67/10, +4.17)

Expected behavior


--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

pylint --version output

pylint-3 2.3.1
astroid 2.3.0
Python 3.8.0b4 (default, Aug 30 2019, 00:00:00) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]

This is on Fedora rawhide with Python 3.8.

The expected behaviour is from Fedora 30 with Python 3.7:

pylint-3 2.3.1
astroid 2.2.5
Python 3.7.4 (default, Jul  9 2019, 16:32:37) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]

Similar issue was reported before (and resolved) as #1328.

@PCManticore
Copy link
Contributor

Thanks, I can reproduce the issue.

@adelton
Copy link
Author

adelton commented Sep 19, 2019

Actually, this does not seem to be Python 3.8 specific. I see the issue on Fedora 31 (run in registry.fedoraproject.org/fedora:31 container) with Python 3.7 as well:

# pylint-3 --version
pylint-3 2.3.1
astroid 2.3.0
Python 3.7.4 (default, Aug 12 2019, 14:45:07) 
[GCC 9.1.1 20190605 (Red Hat 9.1.1-2)]

Is astroid (2.3.0 vs. 2.2.5 on Fedora 30 where the issue does not manifest itself) the culprit?

adelton added a commit to swidtags/rpm2swidtag that referenced this issue Sep 19, 2019
@SamyCookie
Copy link

SamyCookie commented Sep 30, 2019

I agree, it's not Python version related issue. I got this one with the new Pylint version and Python 3.5 :

pylint 2.4.2
astroid 2.3.1
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516]

and I think @adelton is right, it is related to astroid version (>= 2.3)

balloob pushed a commit to home-assistant/core that referenced this issue Oct 7, 2019
* Upgrade pylint to 2.4.2 and astroid to 2.3.1

https://pylint.readthedocs.io/en/latest/whatsnew/2.4.html
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-1
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-2

* unnecessary-comprehension fixes

* invalid-name fixes

* self-assigning-variable fixes

* Re-enable not-an-iterable

* used-before-assignment fix

* invalid-overridden-method fixes

* undefined-variable __class__ workarounds

pylint-dev/pylint#3090

* no-member false positive disabling

* Remove some no longer needed disables

* using-constant-test fix

* Disable import-outside-toplevel for now

* Disable some apparent no-value-for-parameter false positives

* invalid-overridden-method false positive disables

pylint-dev/pylint#3150

* Fix unintentional Entity.force_update override in AfterShipSensor
adelton added a commit to swidtags/rpm2swidtag that referenced this issue Oct 14, 2019
adelton added a commit to swidtags/rpm2swidtag that referenced this issue Jan 6, 2020
adelton added a commit to swidtags/rpm2swidtag that referenced this issue Jan 6, 2020
adelton added a commit to swidtags/rpm2swidtag that referenced this issue Jan 6, 2020
@Mi-La
Copy link

Mi-La commented Jan 21, 2020

Hi, any plans to fix it? Or are there any problems causing that it cannot be fixed? I'm not happy to use the self.__class__ workaround. Do you have any suggestions how to workaround it nicely? Is it a bad habit to use __class__ at all?
(I get this error E0602: Undefined variable '__class__' (undefined-variable) with pylint 2.4.4 and python 3.6.9).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants