mypy-friendly compat functions handling

This commit is contained in:
Dima Gerasimov 2020-10-31 02:48:00 +00:00 committed by karlicoss
parent 3a9e3e080f
commit 96be32aa51
2 changed files with 13 additions and 3 deletions

View file

@ -280,14 +280,24 @@ tzdatetime = datetime
fromisoformat: Callable[[str], datetime]
import sys
if sys.version_info.minor >= 7:
if sys.version_info[:2] >= (3, 7):
# prevent mypy on py3.6 from complaining...
fromisoformat_real = datetime.fromisoformat # type: ignore[attr-defined]
fromisoformat_real = datetime.fromisoformat
fromisoformat = fromisoformat_real
else:
from .py37 import fromisoformat
if sys.version_info[:2] >= (3, 8):
from typing import Literal
else:
if TYPE_CHECKING:
from typing_extensions import Literal
else:
# erm.. I guess as long as it's not crashing, whatever...
Literal = Union
# TODO doctests?
def isoparse(s: str) -> tzdatetime:
"""

View file

@ -23,7 +23,7 @@ def default_policy() -> Policy:
return cast(Policy, user_config.tz.policy)
except Exception as e:
# todo meh.. need to think how to do this more carefully
# rationale: do not mess with user's data until they want
# rationale: do not mess with user's data unless they want
return 'keep'