Вот мой код, использующий старый универсальный синтаксис, который работает как во время выполнения, так и с mypy:
Код: Выделить всё
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)
Код: Выделить всё
from collections.abc import Callable
from typing import TypeAlias, Unpack
type RK_function_args = tuple[float, int]
# Original function type
type RK_function = Callable[[RK_function_args], int]
# New function type with an additional int argument
type RK_functionBIS = Callable[[Unpack[RK_function_args], int], int]
def a(a1: float, b2 : int) -> int:
return 1
bis: RK_functionBIS=a
res: int = bis(1.0, 2, 3)
тип «Callable[[float, int, int], int] ]", переменная имеет тип
"Callable[[VarArg(*tuple[*tuple[float, int], int])], int]")
[assignment]
Подробнее здесь: https://stackoverflow.com/questions/792 ... mypy-error
Мобильная версия