Skip to content

try from typing import ParamSpec except from typing_ext import ParamSpec not working #16903

Closed as not planned
@ghost

Description

Bug Report
try-except imported ParamSpec is unusable.

try:
    from typing import ParamSpec
except ImportError:
    from typing_extensions import ParamSpec

This makes ParamSpec("P") become an invaild type.

To Reproduce

from typing import Callable

try:
    from typing import ParamSpec  # type: ignore[attr-defined,unused-ignore]
except ImportError:
    from typing_extensions import ParamSpec  # type: ignore[import,unused-ignore]

P = ParamSpec("P")

def func(arg: Callable[P, None]) -> None:
    return None

Expected Behavior
No error

Actual Behavior
error: The first argument to Callable must be a list of types, parameter specification, or "..." [valid-type]

Your Environment

  • OS: Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-94-generic x86_64)
  • Mypy version used: 1.8.0 (compiled: yes)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8.18

Reproduce repository

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