Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeAliasType is always generic when type_params=() is passed. #124498

Closed
Daraan opened this issue Sep 25, 2024 · 0 comments
Closed

TypeAliasType is always generic when type_params=() is passed. #124498

Daraan opened this issue Sep 25, 2024 · 0 comments
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@Daraan
Copy link

Daraan commented Sep 25, 2024

Bug report

Bug description:

I realized that the type_params parameter of TypeAliasType 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.

from typing import List, TypeAliasType, TypeVar

# < Errors like expected >

Simple = TypeAliasType("Simple", int)
try:
    Simple[int]
except TypeError:
   print("Expected: Simple is not subcriptable")

# Not allowed assignment
T = TypeVar('T')
MissingTypeParamsErr = TypeAliasType("MissingTypeParamsErr", List[T])
assert MissingTypeParamsErr.__type_params__ == ()
assert MissingTypeParamsErr.__parameters__ == ()

try:
    MissingTypeParamsErr[int]
except TypeError:
   print("Expected: Simple is not subcriptable")

# < unexpected cases >
    
MissingTypeParams = TypeAliasType("MissingTypeParams", List[T], type_params=())
assert MissingTypeParams.__type_params__ == ()
assert MissingTypeParams.__parameters__ == ()
# These cases do not raise an error
MissingTypeParams[int]
MissingTypeParams[[]]
MissingTypeParams[()]

# This also do not raise an error
Simple2 = TypeAliasType("Simple2", int, type_params=())
assert Simple2 .__type_params__ == ()
assert Simple2 .__parameters__ == ()
Simple2[int]
Simple2[[]]
Simple2[()]

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

@Daraan Daraan added the type-bug An unexpected behavior, bug, or error label Sep 25, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Sep 25, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 26, 2024
…rams=()` (pythonGH-124499)

(cherry picked from commit abe5f79)

Co-authored-by: sobolevn <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 26, 2024
…rams=()` (pythonGH-124499)

(cherry picked from commit abe5f79)

Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Sep 26, 2024
…arams=()` (GH-124499) (#124604)

gh-124498: Fix `TypeAliasType` not to be generic, when `type_params=()` (GH-124499)
(cherry picked from commit abe5f79)

Co-authored-by: sobolevn <mail@sobolevn.me>
Yhg1s pushed a commit that referenced this issue Sep 30, 2024
…arams=()` (GH-124499) (#124603)

gh-124498: Fix `TypeAliasType` not to be generic, when `type_params=()` (GH-124499)
(cherry picked from commit abe5f79)

Co-authored-by: sobolevn <mail@sobolevn.me>
@Daraan Daraan closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants