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

Skip to content

TypeAliasType not raising TypeError when it is has no parameters #468

Closed
@Daraan

Description

@Daraan

When using a TypeAliasType without type_params it should raise an error which it currently doesn't:

from typing import TypeAliasType as typing_TA
from typing_extensions import TypeAliasType

# this should raise an error
Simple = TypeAliasType("Simple", int)
Simple_typing = typing_TA("Simple", int)
try:
   Simple[str]  # No TypeError
except TypeError:
   print("TypeError raised like expected")
else:
   print("No type error was raised.")  # <-- will be printed

Simple_typing[str] # will raise TypeError

However, currently in 3.12+ when using type_params=() the code unexpectedly allows subscription.
See also cpython issue #124498 and its PR. This issue likely needs an upstream decision first if the following case is intended or a bug:

from typing import TypeAliasType as typing_TA
Simple2 = typing_TA("Simple", int, type_params=())
Simple2[str]  # no type error for typing.TypeAliasType

Also related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions