From 6fc882860b09842c4418c2d61e37407cf681e227 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Mon, 18 May 2020 17:16:31 -0400 Subject: [PATCH] Add type hints for the zoneinfo module (#4038) This is the implementation for PEP 615: https://www.python.org/dev/peps/pep-0615/ It is present starting in 3.9.0 beta 1. --- stdlib/3.9/zoneinfo/__init__.pyi | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 stdlib/3.9/zoneinfo/__init__.pyi diff --git a/stdlib/3.9/zoneinfo/__init__.pyi b/stdlib/3.9/zoneinfo/__init__.pyi new file mode 100644 index 000000000..6e56abf2c --- /dev/null +++ b/stdlib/3.9/zoneinfo/__init__.pyi @@ -0,0 +1,45 @@ +import os +import typing +from datetime import datetime, tzinfo +from typing import ( + Any, + Iterable, + Optional, + Protocol, + Sequence, + Set, + Type, + Union, +) + +_T = typing.TypeVar("_T", bound="ZoneInfo") + +class _IOBytes(Protocol): + def read(self, __size: int) -> bytes: ... + def seek(self, __size: int, __whence: int = ...) -> Any: ... + +class ZoneInfo(tzinfo): + @property + def key(self) -> str: ... + def __init__(self, key: str) -> None: ... + @classmethod + def no_cache(cls: Type[_T], key: str) -> _T: ... + @classmethod + def from_file( + cls: Type[_T], __fobj: _IOBytes, key: Optional[str] = ... + ) -> _T: ... + @classmethod + def clear_cache(cls, *, only_keys: Iterable[str] = ...) -> None: ... + +# Note: Both here and in clear_cache, the types allow the use of `str` where +# a sequence of strings is required. This should be remedied if a solution +# to this typing bug is found: https://github.com/python/typing/issues/256 +def reset_tzpath( + to: Optional[Sequence[Union[os.PathLike, str]]] = ... +) -> None: ... +def available_timezones() -> Set[str]: ... + +TZPATH: Sequence[str] + +class ZoneInfoNotFoundError(KeyError): ... +class InvalidTZPathWarning(RuntimeWarning): ...