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 does not recognize type parameter after use of Concatenate and cannot be subscripted #124904

Closed
Daraan opened this issue Oct 2, 2024 · 3 comments
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@Daraan
Copy link

Daraan commented Oct 2, 2024

Bug report

Bug description:

After using Concatenate to recursively replace a ParamSpec of a TypeAliasType, another subscription with a type param is possible but the type param is not recognized.

In the last part the following code (C2T = C2[T] # <--- should create a generic), however it's parameters are empty and it cannot be subscripted further:

Consider the following code sample, also availiable on pyright playground

from typing import TypeAliasType, Concatenate, ParamSpec, Any, TypeVar
from collections.abc import Callable

# (**P) -> str
type C[**P] =  Callable[P, str]

T = TypeVar("T")
P2 = ParamSpec("P2")

# (int, **P2) -> str
C2 = C[Concatenate[int, P2]]

# OK
# (T) -> str
C1T = C[T]
# (str) -> str
C1_str = C1T[str]

# -------- 

# (int, T) -> str
C2T = C2[T]   # <--- does not create a generic
print(C2T.__parameters__)  # <-- is empty
# () 

# (int, str) -> str
C2_str = C2T[str]  # <-- cannot be subscripted
# TypeError: C[(<class 'int'>, ~T)] is not a generic class

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@Daraan Daraan added the type-bug An unexpected behavior, bug, or error label Oct 2, 2024
@Daraan Daraan changed the title TypeAliasType does not recognize type parameter after recusrive use of Concatenate and cannot be subscripted TypeAliasType does not recognize type parameter after use of Concatenate and cannot be subscripted Oct 2, 2024
@tomasr8
Copy link
Member

tomasr8 commented Oct 2, 2024

I think this will be fixed by this PR #124512
When I run your example on that branch, I get non-empty __parameters__:

>>> C2T = C2[T]
>>> C2T.__parameters__
(~T,)

@Eclips4
Copy link
Member

Eclips4 commented Oct 2, 2024

Thanks for the investigation, Tomas.
So I guess we can close this as a duplicate of #124445?

@Daraan
Copy link
Author

Daraan commented Oct 2, 2024

It's definitely similar, I'll close it and will check it later again. Thanks for checking!

@Daraan Daraan closed this as completed Oct 2, 2024
@Eclips4 Eclips4 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 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

3 participants