mashumaro icon indicating copy to clipboard operation
mashumaro copied to clipboard

Add support for typing.Pattern and re.Pattern

Open Fatal1ty opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. There is a standard type Pattern https://docs.python.org/3/library/typing.html#typing.Pattern. Support for annotations re.Pattern and typing.Pattern could be useful.

Describe the solution you'd like A Pattern object can be deserialized from string using re.compile:

print(type(re.compile("[a-z]+")))  # <class 're.Pattern'>

For serialization we can use pattern property:

print(repr(re.compile("[a-z]+").pattern))  # '[a-z]+'

I'm not sure if we should distinguish different variations of a generic Pattern type. We can treat them all like Pattern[str] unless there is a reasonable use of Pattern[bytes].

Fatal1ty avatar Apr 25 '23 10:04 Fatal1ty