Skip to content

TypeAliasType does not recognize type parameter after use of Concatenate and cannot be subscripted #124904

Closed as not planned

Description

@Daraan

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 2, 2024
  2. 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[/+] on Oct 2, 2024
  3. tomasr8 commented on Oct 2, 2024

    @tomasr8
    Member

    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,)
  4. Eclips4 commented on Oct 2, 2024

    @Eclips4
    Member

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

  5. Daraan commented on Oct 2, 2024

    @Daraan
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions