pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Method override completion doesn't return the correct return type

Open StellaHuang95 opened this issue 10 months ago • 3 comments

Environment data

  • Language Server version:2024.4.1

Code Snippet

# file1.py
class Parent:
    def method(self) -> str:
        pass
# file2.py
from sys import version
from file1 import Parent

print(version)

class Child(Parent):
    def meth # <- trigger completion here

Repro Steps

  1. Type meth and accept completion

Expected behavior

class Child(Parent):
    def method(self) -> str:
        return super().method()

Actual behavior

class Child(Parent):
    def method(self) -> version:
        return super().method()

The return type is wrong.

StellaHuang95 avatar Apr 03 '24 21:04 StellaHuang95

I debugged a little bit and found the wrong type is returned from https://github.com/microsoft/pyrx/blob/50b9544f921007da1d758ac69e61081987c6a65b/packages/pylance-internal/src/services/typeStringGenerator.ts#L60

I can take a closer look later. Also tagging @heejaechang

StellaHuang95 avatar Apr 03 '24 22:04 StellaHuang95

Similar, if not the same: https://github.com/microsoft/pylance-release/issues/5534

Viicos avatar Apr 04 '24 07:04 Viicos

Looks like it only repros if the other symbol imported is the same type as the return type.

StellaHuang95 avatar Apr 04 '24 18:04 StellaHuang95

Can no longer repro this with v2024.5.1

luabud avatar Jun 05 '24 18:06 luabud

Doesn't repro for me with the latest pylance version 2024.5.103. Closing it out.

StellaHuang95 avatar Jun 05 '24 18:06 StellaHuang95

This was a duplicate of https://github.com/microsoft/pylance-release/issues/5693 which was fixed in 2024.4.100.

debonte avatar Jun 05 '24 18:06 debonte