Skip to content

Why does pyright deduce Mapping[Unknown, Unknown] in this case? #7861

Answered by erictraut
Holt59 asked this question in Q&A
Discussion options

You must be logged in to vote

I presume that you have strict mode enabled because pyright does not generate any type errors for this code in standard mode.

I'm guessing that _K and _V are type variables with no explicit upper bound, in which case they have implicit upper bounds of object. I can't tell from your code snippet wither _K and _V are scoped to a class. I'm guessing that they're not.

A simplified version of the function should make it more clear why pyright narrows _V to Mapping[Unknown, Unknown] in this case.

def func[_V](value: _V):
    if isinstance(value, Mapping):
        reveal_type(value) # Mapping[Unknown, Unknown]

Here value could be of any type including a Mapping. The type arguments are unknown, s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Holt59
Comment options

Answer selected by Holt59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants