[Python-ideas] Re: Structure Pattern for annotation

2021-10-17 Thread Joren Hammudoglu
I guess you could work around this by exploiting the slicing operator: GenericClass[:(A, B)] It makes sense to use the : in the context of typing, but I can see how this syntax can be confusing. The least confusing implementation I could think of is to limit the use of GenericClass[:_] to tuple

[Python-ideas] Re: Structure Pattern for annotation

2021-10-15 Thread Jelle Zijlstra
El vie, 15 oct 2021 a las 14:42, Abdulla Al Kathiri (< alkathiri.abdu...@gmail.com>) escribió: > I don’t understand why tuple structure is not supported already. It makes > reading the function signature a breeze and very natural. You can also do > it without parentheses which mimics the return of

[Python-ideas] Re: Structure Pattern for annotation

2021-10-15 Thread Abdulla Al Kathiri
I don’t understand why tuple structure is not supported already. It makes reading the function signature a breeze and very natural. You can also do it without parentheses which mimics the return of multiple objects often seen in functions(def func(*args: int) -> str, [int]) > On 14 Oct 2021, at

[Python-ideas] Re: Structure Pattern for annotation

2021-10-15 Thread Abdulla Al Kathiri
> On 14 Oct 2021, at 12:21 PM, Steven D'Aprano wrote: > > > Why abbreviate list and tuple but not string? > Empty strings would be confusing as a type unless you mean a Literal empty string. We just limit the picture of the type to lists, tuples, dicts, and sets. Builtin most often use

[Python-ideas] Re: Structure Pattern for annotation

2021-10-15 Thread Ricky Teachey
On Fri, Oct 15, 2021 at 1:06 PM Finn Mason wrote: > I love the proposal for dicts, but I agree that this discourages duck > typing. Could the curly braces notation represent Mapping, not dict > specifically? > > +1 to shortening tuples but not other sequences. > > > -- > Finn Mason > That might

[Python-ideas] Re: Structure Pattern for annotation

2021-10-15 Thread Finn Mason
I love the proposal for dicts, but I agree that this discourages duck typing. Could the curly braces notation represent Mapping, not dict specifically? +1 to shortening tuples but not other sequences. -- Finn Mason On Thu, Oct 14, 2021, 6:46 AM Paul Moore wrote: > On Thu, 14 Oct 2021 at 13:04

[Python-ideas] Re: Structure Pattern for annotation

2021-10-14 Thread Ricky Teachey
On Thu, Oct 14, 2021 at 8:46 AM Paul Moore wrote: > > ...maybe the energy focused on "making basic types easier to write" > should be focused on making protocols easier to write, instead. > > Paul > + a billion Rick. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about g

[Python-ideas] Re: Structure Pattern for annotation

2021-10-14 Thread Paul Moore
On Thu, 14 Oct 2021 at 13:04, Ricky Teachey wrote: > > I think all of this additional syntax is just a mistake. > > The reason is it will encourage people to not properly annotate their input > types for duck typing. Some of these shortcuts might be nice for output > types. But the more general

[Python-ideas] Re: Structure Pattern for annotation

2021-10-14 Thread Ricky Teachey
I think all of this additional syntax is just a mistake. The reason is it will encourage people to not properly annotate their input types for duck typing. Some of these shortcuts might be nice for output types. But the more general trying.Mapping, typing.Sequence and friends should be preferred f

[Python-ideas] Re: Structure Pattern for annotation

2021-10-14 Thread Alex Waygood
I agree with Steven. I very much like Abdulla's proposed syntax for dicts, TypedDicts and sets. But I'm not sure that the idea for `Annotated` is workable, and the proposal for lists seems too prone to ambiguity, given how extensively square brackets are already used in typing syntax. One ques

[Python-ideas] Re: Structure Pattern for annotation

2021-10-14 Thread Steven D'Aprano
On Thu, Oct 14, 2021 at 12:32:57AM +0400, Abdulla Al Kathiri wrote: > Today I found myself write a function that returns a tuple of list of > list of strings (tuple[list[list[str]], list[list[str]]]). Wouldn’t it > easier to read to write it like the following: > ([[str]], [[str]])? Not really

[Python-ideas] Re: Structure Pattern for annotation

2021-10-13 Thread David Mertz, Ph.D.
I find myself using exactly that "picture of the data" approach informally for code I don't plan on formally type checking (but want to show intent). E.g. def myfun(data: {str: [CustomType]}) -> [(int, OtherType)]: ... Maybe it's a bad habit, but it feels easier to parse visually than the real `