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

a subclass member variable is not recognized as the same variable in superclass unless it has an explicit type hint #5890

Open
adusamr opened this issue May 17, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@adusamr
Copy link

adusamr commented May 17, 2024

Environment data

  • Language Server version: 2024.5.1
  • OS and version: linux x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.10
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: basic

Actual behavior

class A:
    def __init__(self, a):
        self.a = a

class B(A):
    def __init__(self, a):
        self.a = a

In this code, self.a in class A and self.a in class B are recognized as different variables.
This causes incorrect behavior of find references or rename variable. Especially the behavior of rename variable easily can break the code.

If you have any type hint of the self.a in the superclass, this does not happen, even if the type hint is undefined.

class A:
    def __init__(self, a):
        self.a: foo = a

class B(A):
    def __init__(self, a):
        self.a = a
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label May 17, 2024
@rchiodo
Copy link
Contributor

rchiodo commented May 17, 2024

Thanks for the issue. I can reproduce this too. Very weird that the type annotation makes us understand that B.a is inherited.

@rchiodo rchiodo added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants