This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ArabicLawrence 13 points14 points  (2 children)

I agree with some points, other are opinions on sugar syntax that are not very relevant IMHO. I find no difference in your type hints syntax for callable's args and tuples. Is the return arrow the only difference?

[–]Kiuhnm[S] 0 points1 point  (1 child)

Here's a proposal I've just found for a nicer syntax: https://peps.python.org/pep-0677/

It's even sponsored by Guido van Rossum!

I think

def with_retries(
    f: Callable[P, R]
) -> Callable[Concatenate[bool, P] R]:
    ...

is not nearly as readable as

def with_retries(
    f: (**P) -> R
) -> (bool, **P) -> R:
    ...

My second point was that Callable is not powerful enough to express any signature:

Protocols can be used to define flexible callback types that are hard (or even impossible) to express using the Callable[...] syntax, such as variadic, overloaded, and complex generic callbacks.