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

genericGenericAlias#13941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jorenham wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromjorenham:generic-GenericAlias

Conversation

jorenham
Copy link
Contributor

I suppose that theoretically speaking (i.e. ignoring type-checkers), this brings support for higher-kinded typing 🤔.

@github-actionsGitHub Actions
Copy link
Contributor

Diff frommypy_primer, showing the effect of this PR on open source code:

pydantic (https://github.com/pydantic/pydantic)- pydantic/v1/typing.py:47: error: Incompatible types in assignment (expression has type "tuple[()]", variable has type "type[GenericAlias]")  [assignment]+ pydantic/v1/typing.py:47: error: Incompatible types in assignment (expression has type "tuple[()]", variable has type "type[GenericAlias[_OriginT_co]]")  [assignment]discord.py (https://github.com/Rapptz/discord.py)- discord/ext/commands/converter.py:1119: error: Return type "Greedy[T]" of "__class_getitem__" incompatible with return type "GenericAlias" in supertype "list"  [override]+ discord/ext/commands/converter.py:1119: error: Return type "Greedy[T]" of "__class_getitem__" incompatible with return type "GenericAlias[type | TypeAliasType]" in supertype "list"  [override]

@JelleZijlstra
Copy link
Member

What problem does this solve? The class is not generic at runtime and I think pretending it is is likely to cause more confusion than it's worth.

@jorenham
Copy link
ContributorAuthor

What problem does this solve?

It makes it possible to annotatetyping.get_origin:

@overload
defget_origin(tp:GenericAlias)->type: ...

Runtime-typing libraries that only accept subscripted types could also benefit from this: If e.g.x=list[int] is allowed butx=list isn't, they are now able to enforce this by annotatingx: GenericAlias[list[Any]] (assuming static type-checker support). If I remember correctly,pydantic requires this is some places, raising a runtime error otherwise.

The class is not generic at runtime and I think pretending it is is likely to cause more confusion than it's worth.

I suppose that's a bit of a chicken/egg story. And in my experience, typeshed usually takes the lead in these kinds of things, and cpython then follows (e.g.#13760).
Also note thatGenericAlias is likely only used by people with thorough knowledge about typing in Python. So I don't expect them to become confused by it beingoptionally generic.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jorenham@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp