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

Overwriting an inherited function with a variable points not to the new function #6306

Closed
Daraan opened this issue Aug 27, 2024 · 1 comment
Assignees
Labels
by design needs repro Issue has not been reproduced yet

Comments

@Daraan
Copy link

Daraan commented Aug 27, 2024

When not using def to overwrite a parent method but using a variable or import instead, the tooltip and signature of the parent is preserved instead of displaying the new one.

Environment data

  • Using with VSCode
  • Pylance version: 2024.8.101 (pyright version 1.1.375, commit d2c0938f)
  • OS and version: Ubuntu 22.04
  • Python version: miniconda: Any

Code Snippet

def externalbar(a: int):
    """external Bar"""
    
class A:
    
    @staticmethod
    def bar(a:int):
        """This is A.bar"""
        
class B(A):
    
    bar = staticmethod(externalbar)
    # or
    # from somemodule import bar
    
    def foo(self):
        self.bar # Tooltip is: "This is A.bar"; expected 'external Bar'

B.bar # "This is A.bar"; expected 'external Bar'

Expected behavior

Expected that B.bar / self.bar links to externalbar and used it as tooltip instead of using A.bar.

CTRL + click should send me to externalbar

Actual behavior

Falls back to A.bar and ignores the overwrite. CTRL + click sends me to A.bar

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 27, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Aug 27, 2024

Thanks for the issue but this is by design. Pylance (and Pyright that Pylance is based upon) is a static based analyzer. Dynamically changing the value of a member at runtime cannot be modeled by Pylance.

I believe the root problem here is it's not defined whether the A.bar definition happens before or after the assignment in B.

See these issues for more information:
microsoft/pyright#6611
microsoft/pyright#2912

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
by design needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants
@rchiodo @Daraan and others