Skip to content

FrozenSet does not behave covariantly with FrozenSet #3928

Closed
@mbenbernard

Description

@mbenbernard

mypy 0.750 behaves strangely when run on the following code snippet:

from typing import FrozenSet

s1: FrozenSet[bool]
s2: FrozenSet[bool]
s3: FrozenSet[int]

reveal_type(s1)     # note: Revealed type is 'builtins.frozenset[builtins.bool]'
reveal_type(s2)     # note: Revealed type is 'builtins.frozenset[builtins.bool]'
reveal_type(s3)     # note: Revealed type is 'builtins.frozenset[builtins.int]'

s2 = s1     # OK
s3 = s1     # error: Incompatible types in assignment (expression has type "FrozenSet[bool]", variable has type "FrozenSet[int]")

As you can see, FrozenSet doesn't seem to behave covariantly, despite the fact that typing.py says otherwise:

FrozenSet = _alias(frozenset, T_co, inst=False)

The only real difference that I see between FrozenSet and the other type aliases defined in typing.py is that it specifies a built-in type as its origin (i.e. 'frozenset') instead of an ABC.

Is this the expected behavior of mypy or a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions