laike9m / Python-Type-Challenges

Master Python typing (type hints) with interactive online exercises!
https://python-type-challenges.zeabur.app
MIT License
516 stars 32 forks source link

Return type for extreme concatenate #115

Closed dennisrall closed 9 months ago

dennisrall commented 9 months ago

In your solution to the extreme concatenate problem you propose:

def transform[T, **P](f: Callable[Concatenate[Any, P], T]):
    def wrapper(value: Person, *args: P.args, **kwargs: P.kwargs) -> T:
        return f(value, *args, **kwargs)

    return wrapper

But if I add the return type of Callable[Concatenate[Person, P], T] to the transform function, the test in line 19 fails.

Is there a better return type or do you recommend skipping it in general?

laike9m commented 9 months ago

Thanks for reporting this issue.

Though, it looks to me to be expected behavior.

Taking it back. I tend to think this is a bug of pyright, or due to some inherent restriction of Python's type system. On our side, not sure there's much we can do.

dennisrall commented 9 months ago

Thanks for the fast response and the great project.

What do you think about adding a hint that the return type should be omitted?

laike9m commented 9 months ago

Thanks for the fast response and the great project.

What do you think about adding a hint that the return type should be omitted?

Sure, fine with me. Feel free to make a PR and I'll approve.