Le 22/08/2018 à 04:12, MRAB a écrit :
On 2018-08-22 02:38, Elazar wrote:
I don't think this change makes sense, but if it's done, there should be another change, with actual implications: There is no way to express the types of the parameters in a lambda - `lambda x: int : x` is obviously a syntax error. Replacing the colon with a different symbol, such as "=>" will make this possible:

     def x => x
     def x: int => x
     def x: int -> int => x

It will also give one less meaning to the colon.

The examples I showed had parens, so your examples could be:

    def (x): x
    def (x: int): x
    def (x: int) -> int: x
With or without allowing `def` to be an equivalent of `lambda`, I think this is a great idea.
To me, someone who understands the following 2 lines:

lambda x, y: x * y
def a(x: float, y: int) -> float: ...

would probably understand the following:

lambda(x: float, y: int) -> float: x * y

(more type hints, I like it!)

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to