Skip to content

Commit

Permalink
Merge pull request #13 from CMEPW/feature/issue/12
Browse files Browse the repository at this point in the history
Fixed a bug on old Python versions (< 3.8)
  • Loading branch information
LeDocteurDesBits committed Mar 3, 2021
2 parents 18e0a6e + 362ed2b commit b435775
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
from abc import ABC
from dataclasses import dataclass, fields, field
from typing import List, Optional, Union, get_type_hints, get_args, get_origin
from typing import List, Optional, Union, get_type_hints

from dataclasses_json import dataclass_json
from pydantic.typing import NoneType
Expand All @@ -11,6 +11,19 @@
from utils.case import camel_case


# HACK: This is a ugly fix for old Python versions
import sys

if sys.version_info < (3, 8):
def get_args(field):
return field.__args__

def get_origin(field):
return field.__origin__
else:
from typing import get_args, get_origin


def default_field(obj):
return field(default_factory=lambda: copy.copy(obj))

Expand Down

0 comments on commit b435775

Please sign in to comment.