Wanted to chime in on the leading underscores workaround –

 

I think this makes sense as a shorthand if we’re forced to provide a name, but the ‘_’ symbol to me is still associated with “unused” rather than “positional” argument, and that this isn’t intuitive unless someone has read the rules in the PEP and knows this is something they need to add to every callable type. I’m also worried about the extra verbosity when many callables may not need to deal with or think about named parameters at all.

 

I’d be supportive of the shorthand where `(int, str) -> float` is still acceptable if we do not have named params.

 

Additionally, what are the concerns with allowing a hybrid of named and unnamed params, ie.:

 

f: (int, str, *, foo: int = ..., **kwargs: str) -> bool

 

 

 

 

From: Steven Troxler <steven.troxler@gmail.com>
Date: Friday, June 11, 2021 at 1:49 PM
To: typing-sig@python.org <typing-sig@python.org>
Subject: [Typing-sig] Re: Compact syntax for Callable: `(Arg1, Arg2) -> Ret`

It might be worth thinking about whether leading underscores make sense. Especially the convention of allowing multiple `_` I do think it might be more intuitive than requiring `/` (my unsubstantiated hunch is that the fraction of users who could guess from context what `_` does without having to use a search engine would be much higher)

I think if we coalesce on a stub-consistent syntax like this for generic Callable, there's still a question of whether to allow a shorthand without argument names for all-positional-argument callables e.g.
```
(int, str) -> float
```
as shorthand for
```
(_: int, _: str, / ) -> float   # if we require the slash
(_: int, _: str) -> float   # if not
```

The downside is more complex syntax with special rules, but it would be nice for our "improved" syntax to be concise for existing `Callable` annotations and the most common, simple cases
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: szhu@fb.com