← 返回首页
Subscripted generic classes should not have independent class variables · Issue #392 · python/typing · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Subscripted generic classes should not have independent class variables #392

New issue
New issue

Description

Currently we have

class A(Generic[T]): x = None A[int].x = 1 A[str].x = 'a' print(A[int].x) # prints 1 print(A[int]().x) # prints None, since type is erased on instantiation

@JukkaL argues and I agree with him, that this looks wrong. Conceptually, there should be only one runtime class. I think we can implement this without loosing the current runtime generic information by tweaking descriptor __dict__ of GenericMeta, so that all assignments and look-ups on subscripted class objects like A[int] will be transferred to the original class object A.

@gvanrossum What do you think?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

  • Open in GitHub Copilot app

Footer

© 2026 GitHub, Inc.