[issue46692] match case does not support regex

2022-02-09 Thread Eric V. Smith
Eric V. Smith added the comment: Good catch, @xtreak. I think something like the discussed (but not implemented) custom matching protocol would be required here. __match_args__ won't work, because it's a special attribute only checked on classes, not instances. Of course, I'm still not sure

[issue46692] match case does not support regex

2022-02-09 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: > There were ideas for exotic matchers such as IsInstance(), InRange(), > RegexMatchingGroup() and so on. https://www.python.org/dev/peps/pep-0622/#custom-matching-protocol The PEP has some mention about a similar use case in custom match protocol

[issue46692] match case does not support regex

2022-02-09 Thread Eric V. Smith
Eric V. Smith added the comment: Looking at PEP 634, the obvious way to add support for this is to have the re.Match object specify Py_TPFLAGS_MAPPING. But I tried that, and then I get this error when using an re.Match object in a match statement: case {'one': x, 'two': y}:

[issue46692] match case does not support regex

2022-02-09 Thread Eric V. Smith
Eric V. Smith added the comment: Oops, slight bug in my code. Use this: import re def f(map): print(f'input={map["one"]} {map["two"]}') match map: case {'one': x, 'two': y}: print(f"match {x} {y}") case _: print("no match") d = {'one':0,

[issue46692] match case does not support regex

2022-02-09 Thread Eric V. Smith
Change by Eric V. Smith : -- components: +Interpreter Core ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46692] match case does not support regex

2022-02-09 Thread Eric V. Smith
New submission from Eric V. Smith : You need to provide more information. Is your concern that re.match objects aren't matched like dicts are, despite looking like a mapping? import re def f(map): print(f'input={m["one"]} {m["two"]}') match map: case {'one': x, 'two': y}:

[issue46692] match case does not support regex

2022-02-09 Thread Ali Rn
Change by Ali Rn : -- components: Regular Expressions nosy: AliRn, ezio.melotti, mrabarnett priority: normal severity: normal status: open title: match case does not support regex type: behavior versions: Python 3.10, Python 3.11 ___ Python tracker