Hello, On Mon, 18 May 2020 13:25:50 +1200 Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> On 18/05/20 1:59 am, Paul Sokolovsky wrote: > > But even > > {(int): str} is a better type annotation for a function than > > Callable[[int], str]. > > I don't agree -- it looks more like some kind of dict type, and > would be better reserved for that purpose. Well, I don't say "ideal", I say "better". The point is that the world learned long ago that any type of information can be represented with just recursive parens: (foo (bar 1 (2) 3)), but some variety in punctuation helps mere humans among us. > > > And if we e.g. talk about making "->" a special operator which would > > allow it to appear in other contexts > > Or maybe we could leverage the new walrus operator and write > > str := (int) With the idea that someone may confuse ":=" for "<-", so we can swap result and argument types comparing to their natural/intuitive order? Well, I guess that's not what I'm talking about. But we indeed can treat ":=" as a function operator in annotations, and write: (int) := str Actually, we don't have to use funky novelties, and mere "-" looks better as a lookalike for "->" than ":=". The following works as expected: ========= from __future__ import annotations def foo(f: (str, int) - int = map, seq: list = None): pass print(foo.__annotations__) import ast print(ast.dump(ast.parse(foo.__annotations__["f"]).body[0])) ========= I'd still consider it a better idea to just make "->" an operator on the AST level. Can stop there, because realistically (or sanely) PEP-0563 annotations would be parsed via an AST (example above). But if there's desire to assign some semantics to it, it can be that of making a tuple, with precedence just above "," operator, so "foo -> bar, 1 -> 2" would evaluate to ((foo, bar), (1, 2)). Worst-case, can add a __rarrow__ dunder. > > -- > Greg -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/56BAIT46CLGQWYEOL7VU54VENG72QCNO/ Code of Conduct: http://python.org/psf/codeofconduct/