I have wanted this and suggested it before for use with typing. 

Defining  protocols is obnoxiously verbose for "struct" like data and keyword
arguments to subscript could help alleviate that.
I often want to write type hint like this:

```
def foo(x: Protocol[id=int, name=str]):
      bar(x)
      baz(x)

def bar(x: Protocol[name=str]): ...

def baz(x: Protocol[id=int]): ...
```

So  I either need to specify more restrictive types than necessary (which often
is not possible because I reuse my functions), or generate a combinatorial
number of Protocols.  Beyond the obvious annoyances that come with having to
generate many protocols, simply naming them is cognitively expensive.  I don't
need to bind an identifier when declaring a Union or specializing a generic but
if I want to say I have a type with some attribute it MUST be named.    


On Fri, Jul 10, 2020 at 10:00 AM Paul Moore <p.f.moore@gmail.com> wrote:
On Fri, 10 Jul 2020 at 17:45, Steven D'Aprano <steve@pearwood.info> wrote:

> I must admit I like the look of this, but I don't know what I would use
> it for.

It feels very much like the sort of "here's some syntax that might
match someone's mental model of something" that is common in languages
that focus on allowing users to build their own DSLs¹ (Lua and Groovy
are two examples of the type of language I'm thinking of, although I
don't know if either has this particular syntax).

Python typically doesn't encourage DSL-style programming, so this type
of "syntax looking for a use case" isn't very popular.

Paul

¹ DSL = Domain Specific Language, in case anyone isn't familiar with the term.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/HUELPGHPCAIFLUKCQ5G7O2LKQFRRZ6CU/
Code of Conduct: http://python.org/psf/codeofconduct/