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

semantic highlight and hints for a TypedDict's get function. #4098

Closed
amotzop opened this issue Mar 17, 2023 · 4 comments
Closed

semantic highlight and hints for a TypedDict's get function. #4098

amotzop opened this issue Mar 17, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@amotzop
Copy link

amotzop commented Mar 17, 2023

Environment data

  • Language Server version: v2023.3.20
  • OS and version: ubuntu 20.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.5

Code Snippet

from typing_extensions import TypedDict

class Cls(TypedDict):
    a: int
    b: str

dct: Cls = {"a": 1, "b": "2"}
dct.get("a")

Repro Steps

  1. Look at the semantic highlighting of the above code.
  2. Put your curser on the get part to see the type hint.

Expected behavior

  1. The get function should be colored as such.
  2. The hint should show the various possible signatures like for a regular overloaded function (where it shows a single signature and you can move between the different signatures manually).

Actual behavior

  1. The get function is uncolored.
  2. The hint looks like get: Overload[(k: Literal['a']) -> int, (k: Literal['a'], default: Any) -> int, (k: Literal['b']) -> str, (k: Literal['b'], default: Any) -> str, (k: str) -> (Any | None), (k: str, default: __TDefault@Cls) -> (Any | __TDefault@Cls)]).
erictraut pushed a commit to microsoft/pyright that referenced this issue Mar 17, 2023
@erictraut
Copy link
Contributor

The problem is that the get symbol for a TypedDict class is completely synthesized by the type checker. It has no declaration. This is handled internally by specifying a _synthesizedType in the associated symbol, but that symbol has no associated declaration. The hover provider and semantic token provider currently operate on declarations. They both have fallback logic to handle symbols without declarations in a reasonable manner, but this fallback logic is different from the mainstream logic.

I've updated the hover provider in the pyright code base to better handle this case.

The semantic token provider in the pylance code base will likewise need to be updated to handle the case where there are no declarations but there is a synthesized type associated with the symbol.

@debonte debonte added the enhancement New feature or request label Mar 17, 2023
@debonte debonte removed their assignment Mar 17, 2023
@rchiodo rchiodo self-assigned this Dec 7, 2023
@kikones34
Copy link

Any updates on this? It appears it's still not behaving as expected.

@rchiodo
Copy link
Contributor

rchiodo commented Oct 22, 2024

I believe it's still being discussed on what to do:
microsoft/pyright#9252

@debonte debonte assigned debonte and unassigned rchiodo Oct 22, 2024
@bschnurr bschnurr added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Nov 4, 2024
@KacieKK
Copy link
Contributor

KacieKK commented Nov 6, 2024

This issue has been fixed in prerelease version 2024.11.100, which we've just released. You can find the changelog here: CHANGELOG.md

@KacieKK KacieKK closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

7 participants