Closed
Description
this code with the old generic syntax works perfectly well
from collections.abc import Callable
from typing import TypeAliasType, Unpack
RK_function_args = TypeAliasType("RK_function_args", tuple[float, int])
# Original function type
RK_function = TypeAliasType("RK_function", Callable[[Unpack[RK_function_args]], int])
# Attempted new function type with an additional int argument
RK_functionBIS = TypeAliasType(
"RK_functionBIS", Callable[[Unpack[RK_function_args], int], int]
)
def ff(a: float, b: int, c: int) -> int:
return 2
bis: RK_functionBIS = ff
res: int = bis(1.0, 2, 3) # OK
print(res)
<
there is no problem assigning the value ff tp bis of type RK_functionBIS.
ff take a float , a int and a a int as argument. And the RK_functionBIS take as argument tuple(float,int,int) unpacked
But it fails with the new new generic syntax
from collections.abc import Callable
from typing import Unpack
type RK_function_args = tuple[float, int]
type RK_function = Callable[[Unpack[RK_function_args]], int]
type RK_functionBIS = Callable[[Unpack[RK_function_args], int], int]
def f(a: float, b: int) -> int:
return 2
def ff(a: float, b: int, c: int) -> int:
return 2
bis: RK_functionBIS = ff
res: int = bis(1.0, 2, 3) # OK
print(res)
error messagee: main.py:17: error: Incompatible types in assignment (expression has type "Callable[[float, int, int], int]", variable has type "Callable[[VarArg(*tuple[*tuple[float, int], int])], int]") [assignment]
note that in both case in can run my code successfully- I am not completely sure this is a bug. Perhaps I just made a mistake but somebody in stackoverflow told me to report it as a bug: