Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ImportError on python <3.7.2 #1733

Merged
merged 3 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions faker/providers/__init__.py
@@ -1,9 +1,11 @@
import re
import string

from typing import Any, Collection, List, Optional, OrderedDict, Sequence, TypeVar, Union
from collections import OrderedDict
from typing import Any, Collection, List, Optional, Sequence, TypeVar, Union

from ..generator import Generator
from ..typing import OrderedDictType
from ..utils.distribution import choices_distribution, choices_distribution_unique

_re_hash = re.compile(r"#")
Expand All @@ -15,7 +17,7 @@

S = TypeVar("S")
T = TypeVar("T")
ElementsType = Union[Collection[T], OrderedDict[T, float]]
ElementsType = Union[Collection[T], OrderedDictType[T, float]]


class BaseProvider:
Expand Down
9 changes: 9 additions & 0 deletions faker/typing.py
@@ -1,3 +1,5 @@
import sys

from datetime import date, datetime, timedelta
from typing import Sequence, TypeVar, Union

Expand All @@ -6,6 +8,13 @@
except ImportError:
from typing_extensions import Literal # type: ignore

if sys.version_info >= (3, 9):
from collections import OrderedDict as OrderedDictType
elif sys.version_info >= (3, 7, 2):
from typing import OrderedDict as OrderedDictType
else:
from typing_extensions import OrderedDict as OrderedDictType # NOQA

DateParseType = Union[date, datetime, timedelta, str, int]
HueType = TypeVar("HueType", str, float, Sequence[int])
SexLiteral = Literal["M", "F"]
Expand Down