[Python-Dev] Re: RFC on Callable Type Syntax

2021-10-17 Thread Serhiy Storchaka
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/


[Python-Dev] Re: PEP 654 except* formatting

2021-10-17 Thread Steven D'Aprano
Rob Cliffe is having problems posting to the Python-Dev list, so he 
posted an alternative suggestion to the Python-Ideas list:

https://mail.python.org/archives/list/python-id...@python.org/message/6KQUQBKFGJSGDNXFZBSM5OXD2ISLIQTT/

Rob's idea is to use "except for ..." with exception groups, instead of 
a new keyword or symbol.


-- 
Steve
___
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/62ZX4T226BCRQE7ZNJPSJNNBAP735K2J/
Code of Conduct: http://python.org/psf/codeofconduct/