Skip to content

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

Closed
@cjolowicz

Description

@cjolowicz

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

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