Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeError: Some type variables (+T) are not listed in Generic[~T] #94607

Closed
Assignees
serhiy-storchakaFidget-Spinner
Labels
3.11only security fixes3.12only security fixestopic-typingtype-bugAn unexpected behavior, bug, or error
@antonagestam

Description

@antonagestam

Bug report

In Python 3.11.0b3 subclasses of generic classes seems to have started requiring explicitly filling in all the super-classes type vars, even though the subclass isn't supposed to be generic in the same variable as the super type.

The behavior is inconsistent and only throws an error if the subclass is also generic.

Minimal reproduction

fromtypingimportGenericfromtypingimportTypeVar# --- baseT_co=TypeVar("T_co",covariant=True)classBase(Generic[T_co]):    ...# --- non-generic subclass, this doesn't throw an errorclassNonGenericSub(Base):    ...# --- subclass generic, in _another_ variableT=TypeVar("T")# this throws an errorclassSub(Base,Generic[T]):    ...

This gives this error:

Traceback (most recent call last):  File "/Users/annevoab/projects/phantom-types/reproduce.py", line 22, in <module>    class Sub(Base, Generic[T]):    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/Users/annevoab/.pyenv/versions/3.11.0b3/lib/python3.11/typing.py", line 1869, in __init_subclass__    raise TypeError(f"Some type variables ({s_vars}) are"    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: Some type variables (+T_co) are not listed in Generic[~T]

Workaround

By explicitly passingobject to fill in the typevar of the super class, the error is surpressed.

classSub(Base[object],Generic[T]):    ...

Your environment

  • CPython versions tested on: Python 3.11.0b3
  • Operating system and architecture: Macos 12.3.1 / Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixestopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp