Skip to content

Sequence | Hashable reduced to Hashable when class is Generic #14311

Closed
@twoertwein

Description

@twoertwein

Bug Report

To Reproduce

from typing import (
    Generic,
    Hashable,
    Sequence,
    TypeVar,
)

T = TypeVar("T")

class Series(Generic[T]):
    def reset_index(self, level: Sequence | Hashable = ...): ...

Series().reset_index(["ab"])  # fails
reveal_type(
    Series().reset_index
)  # Revealed type is "def (level: typing.Hashable =) -> Any"

class Series2:  # not generic
    def reset_index(self, level: Sequence | Hashable = ...): ...

Series2().reset_index(["ab"])  # works
reveal_type(
    Series2().reset_index
)  # Revealed type is "def (level: Union[typing.Sequence[Any], typing.Hashable] =) -> Any"```

Expected Behavior

Series().reset_index(["ab"]) is accepted since list[str] is a Sequence.

Actual Behavior

Sequence | Hashable is reduced to just Hashable which is incompatible with list[str].

Your Environment

  • Mypy version used: 0.991
  • Python version used: 3.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions