Skip to content

Commit

Permalink
feat(types): implement os.PathLike
Browse files Browse the repository at this point in the history
  • Loading branch information
David Arnold authored Dec 10, 2019
1 parent b6fcb06 commit df7cbe0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mashumaro/serializer/base/metaprogramming.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import pathlib
import enum
import uuid
import typing
Expand Down Expand Up @@ -270,6 +272,8 @@ def inner_expr(arg_num=0, v_name='value'):
elif issubclass(origin_type, typing.Sequence):
if is_generic(ftype):
return f'[{inner_expr()} for value in {value_name}]'
elif issubclass(origin_type, os.PathLike):
return f'{value_name}.__fspath__()'
elif issubclass(origin_type, enum.Enum):
return f'{value_name} if use_enum else {value_name}.value'
elif origin_type is int:
Expand Down Expand Up @@ -407,6 +411,8 @@ def inner_expr(arg_num=0, v_name='value'):
elif issubclass(origin_type, typing.Sequence):
if is_generic(ftype):
return f'[{inner_expr()} for value in {value_name}]'
elif issubclass(origin_type, os.PathLike):
return f'pathlib.Path({value_name})'
elif issubclass(origin_type, enum.Enum):
return f'{value_name} if use_enum ' \
f'else {type_name(origin_type)}({value_name})'
Expand Down

0 comments on commit df7cbe0

Please sign in to comment.