Skip to content

Infer type from in container check #10977

Closed as not planned
Closed as not planned
@Dreamsorcerer

Description

@Dreamsorcerer
m: Mapping[str, str]
v: Union[str, bytes]
if v in m:
    m[v]

This produces:
Invalid index type "Union[str, bytes]" for "Mapping[str, str]"; expected type "str" [index]

But, we just checked that the value is in the mapping; so firstly, it most certainly is a valid index, but secondly, we can also infer that the variable is in fact str type.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions