Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
twoertwein opened this issue Dec 17, 2022 · 2 comments
Closed

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

twoertwein opened this issue Dec 17, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@twoertwein
Copy link

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
@erictraut
Copy link

This appears to have been fixed in mypy 1.0.0.

@hauntsaninja
Copy link
Collaborator

Fixed in #14178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants