Skip to content

Commit

Permalink
Fix ImportError on python <3.7.2 (#1733)
Browse files Browse the repository at this point in the history
* Fix ImportError on python <3.7.2

7883502 added an import of
`typing.OrderedDict` but this was added in Python 3.7.2[1] resulting in
an import failure for python versions before this.

[1] https://docs.python.org/3/library/typing.html#typing.OrderedDict


Co-authored-by: Matt Hughes <matt.hughes@ly.st>
Co-authored-by: Flavio Curella <89607+fcurella@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 13, 2022

Verified

This commit was signed with the committer’s verified signature.
not-an-aardvark Teddy Katz
1 parent 1c044e0 commit 97297a9
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions faker/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -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"#")
@@ -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:
9 changes: 9 additions & 0 deletions faker/typing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

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

@@ -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"]

0 comments on commit 97297a9

Please sign in to comment.