On Tue, Sep 13, 2022 at 8:44 AM Matt del Valle <matthew...@gmail.com>
wrote:and bind them

> match val:
>     case [*str()]:
>         ...
>
>
> Where 'val' will match an iterable containing zero or more strings.
>
> This should also work with more complex sub-patterns, like:
>
> match humans:
>     case [
>         *{
>             'name': str(),
>             'age': int(),
>         }
>     ]:
>         ...
>
>
> Where 'humans' should match an iterable of zero or more mappings where
> each mapping contains the keys 'name' and 'age' (and where the value for
> name is a string and the value for age is an int).
>

I haven't yet used pattern matching, but even without that context, this
strikes me as mathicn on type, rather than value.

which doesn't, in my mind, belong in code that's going to run during run
time.

I wouldn't write:

if obj and all( isinstance(o, str) for o in obj):
    do_something

so why would I use it in pattern matching?

Granted, the distinction between type and value gets a bit messy in Python,
but I"d think:

each mapping contains the keys 'name' and 'age'
>

would be value, but:


> (and where the value for name is a string and the value for age is an int).
>

would be type.

I do see that kind of checking to be useful, for, e.g. unpacking JSON data,
but I'm not sure this is where it belongs -- that kind of checking, to me,
is validation of the JSON, defining the structure belongs in a different
place, in a different way.

I would be interested in hearing about the use cases you have in mind, and
where that fits into  the whole type vs value checking continuum.

-CHB


 --
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/5ZJUTZVIVEZTAIKTEIF2BQJ55KXMY47G/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to