[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

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

2021-10-15 Thread Guido van Rossum
On Fri, Oct 15, 2021 at 12:22 PM Pradeep Kumar Srinivasan < gohan...@gmail.com> wrote: > Thanks for the responses, everyone. Overall, it seems like there were no > strong objections to the proposal. > > I didn't hear much about Question 2, though: Should we propose features > beyond present-day

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

2021-10-15 Thread Pradeep Kumar Srinivasan
Thanks for the responses, everyone. Overall, it seems like there were no strong objections to the proposal. I didn't hear much about Question 2, though: Should we propose features beyond present-day `Callable` in the same PEP or defer it to a future PEP? In case that question got lost in the

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

2021-10-12 Thread Łukasz Langa
> On 12 Oct 2021, at 00:09, Erik Demaine wrote: > > Another possibility would be that functions can't be used as their types > directly, but need a casting operator like so: > > ``` > def add_converter(self, converter: typeof(data_to_table)) -> None: > self.converter = converter >

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

2021-10-11 Thread Erik Demaine
My apologies! Must be an issue with my email client rendering. Erik On Mon, 11 Oct 2021, Guido van Rossum wrote: On Mon, Oct 11, 2021 at 3:22 PM Erik Demaine wrote: On Mon, 11 Oct 2021, Guido van Rossum wrote: No, I didn't write that, Lukasz did. > I always found the

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

2021-10-11 Thread Guido van Rossum
On Mon, Oct 11, 2021 at 3:22 PM Erik Demaine wrote: > On Mon, 11 Oct 2021, Guido van Rossum wrote: > No, I didn't write that, Lukasz did. > I always found the following more obvious: > > > > def data_to_table(d: Iterable[Mapping[str, float]], *, sort: bool = > False, reversed: bool = False) ->

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

2021-10-11 Thread Erik Demaine
On Mon, 11 Oct 2021, Guido van Rossum wrote: I always found the following more obvious: def data_to_table(d: Iterable[Mapping[str, float]], *, sort: bool = False, reversed: bool = False) -> Table:     ... @dataclass class Stream:     converter: data_to_table | None     def

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

2021-10-11 Thread gohanpra
1. Barry Warsaw > This means that any PEP which proposes syntactic changes to support typing > features must also address the implications of those syntax changes for the > general Python language. PEP 646 (Variadic Generics) is a good example of > this. Early on we recognized that the

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

2021-10-11 Thread Guido van Rossum
On Mon, Oct 11, 2021 at 1:52 AM Łukasz Langa wrote: > > On 7 Oct 2021, at 18:41, S Pradeep Kumar wrote: > > Note that we considered and rejected using a full def-signature syntax > like > > (record: PurchaseRecord, permissions: List[AuthPermission], /) -> > FormattedItem > > because

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

2021-10-11 Thread Jim J. Jewett
It isn't clear to me that reusing the inspect.Signature object was even considered. If it was rejected as too complicated for most signatures, please put that in the PEP. My own opinion, admittedly not as a typing fan, is that if you need enough details to want more than Callable, then you

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

2021-10-11 Thread jack . jansen
If I can make a wild suggestion: why not create a little language for type specifications? If you look at other programming languages you’ll see that the “type definition sub-language” is often completely different from the “execution sub-language”, with only some symbols in common and used in

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

2021-10-11 Thread Patrick Reader
On 11/10/2021 16:45, Steven Troxler wrote: > https://docs.google.com/document/d/1oCRBAAPs3efTYoIRSUwWLtOr1AUVqc8OCEYn4vKYjGI/edit?usp=sharing I think ParamSpecs should not have any special syntax. `**P` looks way too much like kwargs, and any other syntax would be totally new precedent. I'd

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

2021-10-11 Thread Patrick Reader
On 11/10/2021 17:03, Steven Troxler wrote: > Personally, I think we should both adopt function-as-a-type and shorthand > syntax, and reject both the XOR and hybrid syntax because function-as-a-type > is convenient for expressing the same things (named, default-value, and > variadic args). +1

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

2021-10-11 Thread Steven Troxler
> Is this also why re-using an actual callable at a type was rejected? The idea to use a function as a type (which Łukasz proposed at the PyCon typing summit) is still under consideration. Our thought was that it would probably be a separate PEP from a syntax change. Personally, I think we

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

2021-10-11 Thread Steven Troxler
We drew up a draft syntax to clarify the three styles that have been discussed in typing-sig: - shorthand syntax, which supports exactly what Callable currently supports - XOR syntax, which would allow a def-like style in addition to shorthand - hybrid syntax, which extends shorthand to support

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

2021-10-11 Thread Łukasz Langa
> On 7 Oct 2021, at 18:41, S Pradeep Kumar wrote: > > Note that we considered and rejected using a full def-signature syntax like > > (record: PurchaseRecord, permissions: List[AuthPermission], /) -> > FormattedItem > > because it would be more verbose for common cases and could lead

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

2021-10-08 Thread S Pradeep Kumar
Thanks for the responses! 1. Chris Angelico: > it looks like the parentheses are mandatory, and they are what define it? Yes, we always expect parens. Like you said, this keeps things consistent, resembles the function signature, and avoids ambiguities. It also won't look like Haskell function

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

2021-10-08 Thread Sergei Lebedev
Thanks for summarizing the PSC position, Barry! I agree that type annotation syntax should be consistent with the rest of the language, but I'm curious why it has to be "standard Python syntax"? Could you elaborate a bit more on the reasoning behind that constraint? Cheers, Sergei On Fri, Oct

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

2021-10-08 Thread Guido van Rossum
On Fri, Oct 8, 2021 at 3:36 PM Barry Warsaw wrote: > On Oct 8, 2021, at 13:02, Sergei Lebedev > wrote: > > > > I agree that type annotation syntax should be consistent with the rest > of the language, but I'm curious why it has to be "standard Python syntax"? > Could you elaborate a bit more on

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

2021-10-08 Thread Barry Warsaw
On Oct 8, 2021, at 13:02, Sergei Lebedev wrote: > > I agree that type annotation syntax should be consistent with the rest of the > language, but I'm curious why it has to be "standard Python syntax"? Could > you elaborate a bit more on the reasoning behind that constraint? Hi Sergei. I

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

2021-10-08 Thread Barry Warsaw
Thanks for thinking more deeply about how we can make type annotations for callables more user friendly. The intersection between the syntax for general Python code and type annotations has been a topic of discussion within the Steering Council (on and off) for quite some time. We intend to

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

2021-10-08 Thread Guido van Rossum
Pradeep, Thanks for all the clarifications. I think it's time that you put together a formal grammar. That should also make clear that "(,) -> int" is disallowed while "(int,) -> int" is allowed. --Guido On Fri, Oct 8, 2021 at 8:50 AM S Pradeep Kumar wrote: > Thanks for the responses! > > 1.

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

2021-10-08 Thread Paul Moore
On Fri, 8 Oct 2021 at 16:29, Jelle Zijlstra wrote: > That's one of the differences between the proposals discussed here. The basic > proposal Pradeep pointed out would not support named arguments, the more > complete syntax favored by Guido (and also by me; 2(a) in Pradeep's email) > would

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

2021-10-08 Thread Guido van Rossum
On Fri, Oct 8, 2021 at 8:31 AM Jelle Zijlstra wrote: > El vie, 8 oct 2021 a las 0:54, Paul Moore () > escribió: > >> Also, note that I automatically used a type of int->int up there. As >> someone else asked, is that form allowed, or is it required to be >> (int)->int? In my view, if we require

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

2021-10-08 Thread Jelle Zijlstra
El vie, 8 oct 2021 a las 0:54, Paul Moore () escribió: > On Fri, 8 Oct 2021 at 03:45, S Pradeep Kumar wrote: > > > Typing-sig has been discussing user-friendly syntax for the type used to > represent callables. [1] Since this affects the Python language syntax, we > wanted to get some high-level

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

2021-10-08 Thread Patrick Reader
How would this work for a function that returns a function? Would you just put it on the def line like this? def foo() -> (int) -> str:     return some_function_from_int_to_str Or would it have to be: def foo() -> ((int) -> str): ... The former is a little confusing to read - at first

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

2021-10-08 Thread Serhiy Storchaka
07.10.21 19:41, S Pradeep Kumar пише: > 1. Syntax to replace Callable > > After a lot of discussion, there is strong consensus in typing-sig about > adding syntax to replace Callable. So, the above example would be > written as: > ```python > def print_purchases( >     user: User, >    

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

2021-10-08 Thread Paul Moore
On Fri, 8 Oct 2021 at 03:45, S Pradeep Kumar wrote: > Typing-sig has been discussing user-friendly syntax for the type used to > represent callables. [1] Since this affects the Python language syntax, we > wanted to get some high-level feedback from you before putting up a detailed > PEP.

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

2021-10-07 Thread Piotr Duda
pt., 8 paź 2021 o 04:48 S Pradeep Kumar napisał(a): > ... > Note that we considered and rejected using a full def-signature syntax like > > (record: PurchaseRecord, permissions: List[AuthPermission], /) -> > FormattedItem > > because it would be more verbose for common cases and could

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

2021-10-07 Thread Chris Angelico
On Fri, Oct 8, 2021 at 1:45 PM S Pradeep Kumar wrote: > The Callable type is also usable as an expression, like in type aliases > `IntOperator = (int, int) -> int` and `cast((int) -> int, f)` calls. > > **Question 1**: Are there concerns we should keep in mind about such a syntax > proposal? >