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

TypeAliasType is always generic whentype_params=() is passed. #124498

Closed
Labels
@Daraan

Description

@Daraan

Bug report

Bug description:

I realized that thetype_params parameter ofTypeAliasType behaves differently when it is omitted vs passing an empty tuple(), in the latter case the resulting instance is always subscriptable. I doubt this is an undocumented feature.

fromtypingimportList,TypeAliasType,TypeVar# < Errors like expected >Simple=TypeAliasType("Simple",int)try:Simple[int]exceptTypeError:print("Expected: Simple is not subcriptable")# Not allowed assignmentT=TypeVar('T')MissingTypeParamsErr=TypeAliasType("MissingTypeParamsErr",List[T])assertMissingTypeParamsErr.__type_params__== ()assertMissingTypeParamsErr.__parameters__== ()try:MissingTypeParamsErr[int]exceptTypeError:print("Expected: Simple is not subcriptable")# < unexpected cases >MissingTypeParams=TypeAliasType("MissingTypeParams",List[T],type_params=())assertMissingTypeParams.__type_params__== ()assertMissingTypeParams.__parameters__== ()# These cases do not raise an errorMissingTypeParams[int]MissingTypeParams[[]]MissingTypeParams[()]# This also do not raise an errorSimple2=TypeAliasType("Simple2",int,type_params=())assertSimple2 .__type_params__== ()assertSimple2 .__parameters__== ()Simple2[int]Simple2[[]]Simple2[()]

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp