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

Special reference __class__ is considered undefined in nested lexical scope. #4032

Closed
emcd opened this issue Jan 18, 2021 · 0 comments · Fixed by #6957
Closed

Special reference __class__ is considered undefined in nested lexical scope. #4032

emcd opened this issue Jan 18, 2021 · 0 comments · Fixed by #6957
Assignees
Labels
Bug 🪲 C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@emcd
Copy link
Contributor

emcd commented Jan 18, 2021

Reproducer

class Something:
    def _enclose( ):
        def __init__( self ):
            print( __class__ )
        return __init__
    __init__ = _enclose( )

something = Something( )

Steps to reproduce

  1. Run pylint --score=no --reports=no --enable=all --disable=missing-module-docstring,missing-class-docstring,multiple-statements,too-few-public-methods,no-method-argument,unused-argument on the reproducer above.
  2. Note that Pylint complains about __class__ being an undefined variable.
  3. Run the reproducer in a Python interpreter and note that it executes correctly.

Current behavior

$ pylint --score=no --reports=no --enable=all --disable=missing-module-docstring,missing-class-docstring,multiple-statements,too-few-public-methods,no-method-argument,unused-argument pylint-bugs/nested_dunder_class.py 
************* Module nested_dunder_class
pylint-bugs/nested_dunder_class.py   4,19 [undefined-variable] Undefined variable '__class__'
$ python3 pylint-bugs/nested_dunder_class.py
<class '__main__.Something'>
$

Expected behavior

No error since this is valid Python.

pylint --version output

$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.6.12 (default, Nov  8 2020, 15:40:05) 
[GCC 5.4.0 20160609]
@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jan 30, 2021
@DanielNoord DanielNoord added the C: undefined-variable Issues related to 'undefined-variable' check label Nov 18, 2021
@DanielNoord DanielNoord added this to the 2.14.3 milestone Jun 15, 2022
@DanielNoord DanielNoord self-assigned this Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants