diff --git a/kats/compat/compat.py b/kats/compat/compat.py index 818967bc..43abc2b6 100644 --- a/kats/compat/compat.py +++ b/kats/compat/compat.py @@ -11,22 +11,34 @@ # Python < 3.8 import importlib_metadata as metadata -from typing import Callable, Union +from typing import Any, Callable, Type, Union + +import packaging from packaging import version as pv +OLD_PACKAGING_VERSION: bool = pv.parse(packaging.__version__) <= pv.parse("21.3") + +# type: ignore +VERSION_TYPE: Type[Any] = ( + Union[pv.Version, pv.LegacyVersion] if OLD_PACKAGING_VERSION else pv.Version +) -V = Union[str, "Version", pv.Version, pv.LegacyVersion] +if OLD_PACKAGING_VERSION: + V = Union[str, "Version", pv.Version, pv.LegacyVersion] +else: + V = Union[str, "Version", pv.Version] class Version: """Extend packaging Version to allow comparing to version strings. Wraps instead of extends, because pv.parse can return either a - pv.Version or a pv.LegacyVersion. + pv.Version or a pv.LegacyVersion for version under 21.3 """ - version: Union[pv.Version, pv.LegacyVersion] + # type: ignore + version: VERSION_TYPE def __init__(self, version: V) -> None: """Parse a version. @@ -36,11 +48,14 @@ def __init__(self, version: V) -> None: version object. """ if isinstance(version, str): - self.version = self._parse(version) + # type: ignore + self.version: VERSION_TYPE = self._parse(version) elif isinstance(version, Version): - self.version = version.version + # type: ignore + self.version: VERSION_TYPE = version.version else: - self.version = version + # type: ignore + self.version: VERSION_TYPE = version def _parse(self, version: str) -> Union[pv.Version, pv.LegacyVersion]: try: @@ -73,6 +88,6 @@ def _compare(self, other: V, method: Callable[[V, V], bool]) -> bool: elif isinstance(other, str): other = self._parse(other) try: - return method(self.version._key, other._key) + return method(self.version._key, other._key) # type: ignore except (AttributeError, TypeError): return NotImplemented diff --git a/requirements.txt b/requirements.txt index c17e0d00..d65dec6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ attrs>=21.2.0 deprecated>=1.2.12 importlib_metadata; python_version < '3.8' +holidays<=0.24 matplotlib>=2.0.0 numpy>=1.21,<1.22 pandas>=1.0.4,<=1.3.5