Skip to content
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

type union operator (PEP 604) cannot be used in type argument for generic class #10106

Closed
cjolowicz opened this issue Feb 18, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@cjolowicz
Copy link
Contributor

cjolowicz commented Feb 18, 2021

Bug Report

mypy reports an error when the type union operator (PEP 604) is used in a type argument for a generic class.

To Reproduce

from typing import Generic, TypeVar

T = TypeVar("T")

class Base(Generic[T]):
    def __init__(self, value: T) -> None:
        self.value = value

class Derived(Base[int | float]):
    pass

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

mypy-generic.py:9:15: error: Type expected within [...]  [misc]
    class Derived(Base[int | float]):
                  ^
mypy-generic.py:9:15: error: Invalid base class "Base"  [misc]
    class Derived(Base[int | float]):
                  ^
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.800
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
strict = True
pretty = True
show_column_numbers = True
show_error_codes = True
show_error_context = True
  • Python version used: 3.10 Python 3.10.0a5 (default, Feb 3 2021, 14:01:21)
  • Operating system and version: Fedora 33 Linux 5.10.7-200.fc33.x86_64 #1 SMP Tue Jan 12 20:20:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
@cjolowicz cjolowicz added the bug mypy got something wrong label Feb 18, 2021
@hauntsaninja
Copy link
Collaborator

Duplicate of #9880

@hauntsaninja hauntsaninja marked this as a duplicate of #9880 Feb 18, 2021
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

2 participants