12.10.21 00:03, Guido van Rossum пише:
> But if I see
> 
>     def Comparison(a: T, b: T) -> Literal[-1, 0, 1]:
>         ...
> 
> my first thought is that it's a comparison function that someone hasn't
> finished writing yet, not a function type -- since if it did have at
> least one line of code in the body, it *would* be that.

I agree. There are also problems with variables substitution (indexing),
union (operator "|") and introspection. We would need to add
__getitem__, __or__, __args__, __parameters__ etc to all functions.
There may be also conflicts with NewType which returns a callable.

But can it be expressed via Protocol?

    class Comparison(Protocol, Generic[T]):
        def __call__(self, /, a: T, b: T) -> Literal[-1, 0, 1]: ...

Then we can just add a decorator which turns a function into class:

    @functype
    def Comparison(a: T, b: T) -> Literal[-1, 0, 1]:
        ...

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ENIIWHG7DX3MTBAHOP6ST43J6MHVQKII/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to