Thanks to visit codestin.com
Credit goes to github.com

Skip to content

About TypeVar, passing a name keyword argument to name keyword and positional parameter gets error #20468

@hyperkai

Description

@hyperkai

*Memo:

  • mypy test.py
  • python test.py
  • pyright test.py # Strict mode
  • mypy 1.19.1
  • Python 3.14.0
  • Windows 11

The doc of TypeVar indicates name parameter is both a keyword and positional parameter as shown below:

class typing.TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False, infer_variance=False, default=typing.NoDefault)

But with mypy, passing a name keyword argument to name keyword and positional parameter gets the error as shown below:

*Memo:

  • No error occurs at runtime.
  • pyright gives no error even with strict mode.
from typing import TypeVar

          # ↓↓↓↓↓
T = TypeVar(name='T')
# Error

error: TypeVar() expects a string literal as first argument

So, mypy should accept a name keyword argument.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions