Skip to content

Mypy fails type-check when using Generic["Something"] instead of Generic[Something] #17584

Closed as not planned
@nerodono

Description

@nerodono

Bug Report

To Reproduce

import typing as t

if t.TYPE_CHECKING:
    Something = t.TypeVar("Something")

class Xxx(t.Generic['Something']):
    ...

def lol(x: Xxx[int]) -> None:
    ...

Expected Behavior

Same as the following code (which is passes the type-check):

import typing as t

if t.TYPE_CHECKING: # to not fail in runtime this should be removed too, however, I wanted to show that minimal changes affect the result
    Something = t.TypeVar("Something")

class Xxx(t.Generic[Something]):
    ...

def lol(x: Xxx[int]) -> None:
    ...

Actual Behavior

main.py:6: error: Free type variable expected in Generic[...]  [misc]
main.py:9: error: "Xxx" expects no type arguments, but 1 given  [type-arg]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.11.0 (compiled: yes)
  • Mypy command-line flags: default
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10

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