basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

no error reported with the non-standard spreading a type var that is bound to a tuple

Open KotlinIsland opened this issue 5 months ago • 5 comments

Description

def f[T: tuple[object, ...]]() -> tuple[*T]: ... # no error reported

there is no error reported here for this runtime crash. but we should still allow it when the annotation isn't evaluated because it's understandable to humans and type checkers

KotlinIsland avatar Sep 29 '25 00:09 KotlinIsland

what error do you expect? this is just unpacking a tuple type into another tuple type right? it's redundant but i don't see how it should be an error

DetachHead avatar Sep 29 '25 09:09 DetachHead

what error do you expect? this is just unpacking a tuple type into another tuple type right? it's redundant but i don't see how it should be an error

he doesn't know

try running it

KotlinIsland avatar Sep 29 '25 10:09 KotlinIsland

  File "/home/me/projects/test/asdf.py", line 1
    def f[T: tuple[object, ...]() -> tuple[*T]: ... # no error reported
         ^
SyntaxError: expected '('

hmm, i think its because your code contains a syntax error?

DetachHead avatar Sep 30 '25 08:09 DetachHead

hmm, i think its because your code contains a syntax error?

hmm, must have been a pebcak or AI slop or something like that

KotlinIsland avatar Sep 30 '25 13:09 KotlinIsland

so this is the crash you're talking about:

Traceback (most recent call last):
  File "/home/me/projects/test/asdf.py", line 1, in <module>
    def f[T: tuple[object, ...]]() -> tuple[*T]: ... # no error reported
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/projects/test/asdf.py", line 1, in <generic parameters of f>
    def f[T: tuple[object, ...]]() -> tuple[*T]: ... # no error reported
                                            ^^
TypeError: Value after * must be an iterable, not typing.TypeVar

DetachHead avatar Oct 01 '25 10:10 DetachHead