Skip to content

Incorrect invalid-type-var check when persisting get method of a fully-annotated dict #2812

@grievejia

Description

@grievejia

Describe the Bug

Minimal repro:

class ThemeStack:
    def __init__(self) -> None:
        self._entries: list[dict[str, str]] = [{}]
        self.get = self._entries[
            -1
        ].get  # pyrefly FP: Attribute `get` cannot depend on type variable `_T`

The error does not make much sense to me: self._entries has an explicit annotation and therefore self._entries[-1] should have a concrete dict type. Its get method shouldn't involve any typevar.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQAqAFjALYwDKALqpQNaIAOunpj6mGGHoB9GRHQRucgBRwYUMAEp6AWgB89AHK50MYaPFX1mwjJjpuAJwjxE9KBDjcA2pgiUvt5OADT0wQC6EfQAvPQ%2BwAC%2BESJW1hpghADmMNyx4Rl2Ds6ucD6paZW6AIwVlRHZuWIAxPRkTlJQpPQAYgAK7gCC3CXYAK7cMPQABjnc0-SUGOi4eZLEDpj0pvTcpBv0AG6oLqjYsDMyjNMgISAT0HAk5IggrQCq3NBK3WBj6IEIKY4CIRJJpGBcE42KhlOgxmxsDAnCp8O4FNwdAZws4LFYOtwxk5RGAhCAjAikU53MB8IkySJbiB2p1SIRuLg2FAKK0%2BqQOmAuuEMDgCItTJAskTYUD0IQRK1ODApswRsQ4IgAPSalmCtlQrKahyazC4ShwTWUCUQKVOGWmTX0SFOeioY7QM4XK3oSXSr47XDEf3oJ4iMjcZimXSHZFwWX5MkAZkI1QATAz0CBEnc%2BF8Yz1oDAKGgsHgiGQs0A

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    typecheckingusabilityUsability & readiness issues identified with running Pyrefly on top OSS projects

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions