Skip to content

Generic argument is not being identified #18933

Open
@Alc-Alc

Description

@Alc-Alc

Bug Report

The code in this mypy playground raises the following error.

Name "T" is not defined  [name-defined]

However, as seen in this pyright playground there is no error, which leads me to believe that the snippet is well defined.

This one is probably related but the revealed types do not seem to match as well (the ? in the type name seems to be rather strange).

mypy

"__main__.Repo[T?, U`-2]"

pyright

"Repo[T@some, U@some]"

To Reproduce (this is the same code as in the mypy playground)

from typing import cast, reveal_type
from collections.abc import Callable

class Repo[T, U]: ...

def some[T, U, **P](func: Callable[P, U]) -> Callable[P, U]:
    def wrapper(*args: P.args, **kwargs: P.kwargs) -> U:
        reveal_type(cast(Repo[T, U], args[0]))
        return func(*args, **kwargs)
    return wrapper

Expected Behavior

No errors from mypy, similar behavior to pyright.

Actual Behavior

I am not sure if mypy is misdiagnosing this, if you feel this is intended behavior I can try raising an issue with pyright.

Your Environment

  • Mypy version used: 1.15.0 (playground)
  • Pyright version used: 1.1.399 (playground)
  • Mypy command-line flags: default settings in mypy playground (if I am not mistaken, there are no extra flags)
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.13 (for both playgrounds)

Thank You

Edit: Simplified the example a bit by removing the bounds and awaitables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-695Issues related to PEP 695 syntax

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions