[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Steven D'Aprano
On Fri, Oct 15, 2021 at 06:17:12PM +0200, Sebastian M. Ernst wrote: > Data = Dict[str, Number] > > @typechecked > def foo(bar: Data): > print(bar) > ``` > > Yes, this is using run-time checks (typeguard), which works just fine. > Only strings as keys and Number objects as values are going

[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Christopher Barker
On Fri, Oct 15, 2021 at 9:20 AM Sebastian M. Ernst wrote: > PEP 589 introduces typed dictionaries, but for a fixed set of predefined > keys (similar to struct-like constructs in other languages). In > contrast, I am looking for an arbitrary number of typed keys/value pairs. > But that's

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Steven D'Aprano
On Fri, Oct 15, 2021 at 06:37:04PM -0400, Ricky Teachey wrote: > You say a soft keyword isn't an option and I understand why, but what about > one that is incredibly unlikely to have been used very often? I'm thinking > of just a simple double underscore: > > >>> a = __ > >>> a > 'a' I

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Jeremiah Paige
On Fri, Oct 15, 2021 at 2:53 PM Chris Angelico wrote: > On Sat, Oct 16, 2021 at 8:22 AM Jeremiah Paige wrote: > > > > Here is a pseudo-program showing where I would like to use this token in > > my own code if it existed. I think besides the cases where one is forced > to > > always repeat the

[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

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Jeremiah Paige
On Fri, Oct 15, 2021 at 3:37 PM Ricky Teachey wrote: > You say a soft keyword isn't an option and I understand why, but what > about one that is incredibly unlikely to have been used very often? I'm > thinking of just a simple double underscore: > > >>> a = __ > >>> a > 'a' > > This would be a

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Ricky Teachey
On Fri, Oct 15, 2021 at 6:02 PM Jeremiah Paige wrote: > > > On Fri, Oct 15, 2021 at 2:32 PM Guido van Rossum wrote: > >> I suspect there won’t be enough support for this proposal to ever make it >> happen, but at the very least could you think of a different token? The >> three left arrows just

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Jeremiah Paige
On Fri, Oct 15, 2021 at 2:32 PM Guido van Rossum wrote: > I suspect there won’t be enough support for this proposal to ever make it > happen, but at the very least could you think of a different token? The > three left arrows just look too weird (esp. in the REPL examples, where > they strongly

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Chris Angelico
On Sat, Oct 16, 2021 at 8:22 AM Jeremiah Paige wrote: > > Here is a pseudo-program showing where I would like to use this token in > my own code if it existed. I think besides the cases where one is forced to > always repeat the variable name as a string (namedtuple, NewType) this > is an easy

[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,

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Guido van Rossum
I suspect there won’t be enough support for this proposal to ever make it happen, but at the very least could you think of a different token? The three left arrows just look too weird (esp. in the REPL examples, where they strongly seem to suggest a false symmetry with the ‘>>>’ prompt. How did

[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

[Python-ideas] Re: Accessing target name at runtime

2021-10-15 Thread Jeremiah Paige
On Fri, Oct 8, 2021 at 4:27 PM Chris Angelico wrote: > On Sat, Oct 9, 2021 at 10:02 AM Jeremiah Paige wrote: > > > > On Fri, Oct 8, 2021 at 2:30 PM Chris Angelico wrote: > >> > >> On Sat, Oct 9, 2021 at 6:24 AM Jeremiah Paige > wrote: > >> > Bellow are some examples of where I believe the

[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Paul Moore
On Fri, 15 Oct 2021 at 18:07, Sebastian M. Ernst wrote: > Ignoring typeguard, my suggestion still stands, although slightly > changed: Annotating a dictionary as described earlier in such a way that > type inference is not required OR in such a way that run-time checkers > have a chance to work

[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

[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Simão Afonso
Just a pointer related to this, typeguard is abandoned. kttps://github.com/agronholm/typeguard/issues/198 ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Sebastian M. Ernst
Hi Paul, all, Am 15.10.21 um 18:49 schrieb Paul Moore: > Mypy correctly rejects this: > [...] interesting. Thanks for trying. > If typeguard doesn't, maybe you need to raise that as a bug against > that project? This is kind of contradicting the design of typeguard. It works on a call level

[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

[Python-ideas] Re: Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Paul Moore
Mypy correctly rejects this: ❯ type .\t.py from numbers import Number from typing import Dict Data = Dict[str, Number] def foo(bar: Data): print(bar) bar[1.0] = b'hello' PS 17:48 00:00.008 C:\Work\Scratch\foo ❯ mypy .\t.py t.py:9: error: Invalid index type "float" for "Dict[str,

[Python-ideas] Type-hinting dictionaries for an arbitrary number of arbitrary key/value pairs? Counterpart to PEP 589?

2021-10-15 Thread Sebastian M. Ernst
Hi all, disclaimer: I have no idea on potential syntax or if it is applicable to a wide audience or if there is already a good solution to this. It is more like a "gap" in the type hint spec that I ran across in a project. In function/method signatures, I can hint at dictionaries for example as