Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Incorrect hover/definition for compound string key #4695

Closed
R-O-C-K-E-T opened this issue Aug 6, 2023 · 2 comments
Closed

Incorrect hover/definition for compound string key #4695

R-O-C-K-E-T opened this issue Aug 6, 2023 · 2 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@R-O-C-K-E-T
Copy link

Description

If a compound string ('prefix' 'suffix') is used as a key when constructing a TypedDict expression where the either the first string or last string section is also a valid key into the TypedDict, then the info/definition when hovering over those segments is incorrect.

Expected behaviour

Either the whole compound string is highlighted and the correct type info for the whole key is shown or no type info should be shown for compound string keys.

Steps

Screenshot from 2023-08-06 14-46-38

class Test(TypedDict):
    prefix: str
    suffix: str
    prefixsuffix: int

def test_taker(val: Test):
    ...


test: Test = {
    'prefix': 'foo',
    'suffix': 'bar',

    'prefix' 'suffix': 30, # Hovering over 'prefix' or 'suffix' on this line produces incorrect hover text and definition location
}
test_taker({'prefix': 'foo', 'suffix': 'bar', 'prefix' 'suffix': 30})  # Again, hovering over 'prefix' or 'suffix' on this line produces incorrect hover text and definition location
@R-O-C-K-E-T R-O-C-K-E-T added the bug Something isn't working label Aug 6, 2023
R-O-C-K-E-T referenced this issue in R-O-C-K-E-T/pyright Aug 6, 2023
Pulled out a helper for finding the type that the string is a key for. Copied
some logic for verifying that the StringNode is the only node within a
StringListNode from the completion logic. There appears to be some jank in the
find definition logic that doesn't verify if a StringNode is the only element
in a StringListNode. https://github.com/microsoft/pyright/issues/5655

https://github.com/microsoft/pyright/issues/5654
@erictraut
Copy link
Contributor

@rchiodo or @debonte, please transfer this to the pylance-relase project since it's related to a language server feature.

I don't know if this is worth addressing since it's such an edge case and the workaround is obvious — replace the compound key strings with a single string literal. I'll leave it to the pylance team to decide whether to address this.

@erictraut erictraut removed the bug Something isn't working label Aug 6, 2023
@rchiodo rchiodo transferred this issue from microsoft/pyright Aug 7, 2023
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 7, 2023
@debonte
Copy link
Contributor

debonte commented Aug 14, 2023

Moving this issue to discussion as an enhancement request for comments and upvotes.

@microsoft microsoft locked and limited conversation to collaborators Aug 14, 2023
@debonte debonte converted this issue into discussion #4719 Aug 14, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants