Skip to content

Commit

Permalink
Merge branch 'blaggacao-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Dec 10, 2019
2 parents b6fcb06 + d501b54 commit b398e41
Show file tree
Hide file tree
Showing 2 changed files with 10 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
4 changes: 4 additions & 0 deletions tests/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime, date, time, timedelta, timezone
from dataclasses import dataclass, InitVar
from queue import Queue
from pathlib import Path
from typing import (
Hashable,
List,
Expand Down Expand Up @@ -80,6 +81,8 @@ class Fixture:
FRACTION_STR = '1/3'
MUTABLE_STRING = MutableString(STR)
MUTABLE_STRING_STR = STR
PATH = Path('.')
PATH_STR = '.'


inner_values = [
Expand Down Expand Up @@ -114,6 +117,7 @@ class Fixture:
(decimal.Decimal, Fixture.DECIMAL, Fixture.DECIMAL_STR),
(fractions.Fraction, Fixture.FRACTION, Fixture.FRACTION_STR),
(MutableString, Fixture.MUTABLE_STRING, Fixture.MUTABLE_STRING_STR),
(Path, Fixture.PATH, Fixture.PATH_STR)
]


Expand Down

0 comments on commit b398e41

Please sign in to comment.