microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 767 forks source link

Rename function must also handle first argument of Annotated if it is string #5600

Open minmax opened 7 months ago

minmax commented 7 months ago

After rename OldName -> NewName, pylance does not update Annotated.

from typing import Annotated
from typing import ClassVar

class NewName:
    pass

class C:
    x: ClassVar[NewName]
    y: Annotated["OldName", int]

Pylance language server 2024.2.105 (pyright version 1.1.351).

heejaechang commented 7 months ago

@minmax not fully following. why did you give "OldName" to Annotated rather than actually type OldName?

basically, why Annotated["OldName", ...] rather than Annotated[OldName, ...] ?

with proper input, rename should work as expected.

debonte commented 7 months ago

It's legal syntax and would be required in a forward-ref scenario, but rename doesn't properly handle it there. Similarly, go to def doesn't work on OldName and it's not colored properly as a type.

class C:
    y: Annotated["OldName", "annotation"]

class OldName:
    pass

image

Interestingly, it works with ClassVar though:

class C:
    y: ClassVar["OldName"]

class OldName:
    pass

image

heejaechang commented 7 months ago

I see so, the asking is make first argument of Annotated as one of place where we recognize string as type like a: "int" or ClassVar["str"] or # type: "myType"?

sounds reasonable.

minmax commented 7 months ago

make first argument of Annotated as one of place where we recognize string as type

yes, that's what I was trying to say