Skip to content

dateutil.tz.tz: Replace IO with protocols #7717

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

Merged
merged 8 commits into from
Apr 27, 2022
Merged
24 changes: 16 additions & 8 deletions stubs/python-dateutil/dateutil/tz/tz.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import datetime
from typing import IO, Any, TypeVar
from typing_extensions import TypeAlias
from typing import Any, Protocol, TypeVar
from typing_extensions import Literal

from ..relativedelta import relativedelta
from ._common import _tzinfo as _tzinfo, enfold as enfold, tzname_in_python2 as tzname_in_python2, tzrangebase as tzrangebase

# TODO: _FileObj is used differently in classes below. Some need a byte stream,
# some a str stream.
_FileObj: TypeAlias = str | IO[Any]
_DT = TypeVar("_DT", bound=datetime.datetime)

ZERO: datetime.timedelta
Expand Down Expand Up @@ -56,8 +53,14 @@ class _ttinfo:
__hash__: Any
def __ne__(self, other): ...

class _TZFileReader(Protocol):
# optional attribute:
# name: str
def read(self, __size: int) -> bytes: ...
def seek(self, __target: int, __whence: Literal[1]) -> object: ...

class tzfile(_tzinfo):
def __init__(self, fileobj: _FileObj, filename: str | None = ...) -> None: ...
def __init__(self, fileobj: str | _TZFileReader, filename: str | None = ...) -> None: ...
def is_ambiguous(self, dt: datetime.datetime | None, idx: int | None = ...) -> bool: ...
def utcoffset(self, dt: datetime.datetime | None) -> datetime.timedelta | None: ...
def dst(self, dt: datetime.datetime | None) -> datetime.timedelta | None: ...
Expand All @@ -84,12 +87,17 @@ class tzrange(tzrangebase):

class tzstr(tzrange):
hasdst: bool
def __init__(self, s: bytes | _FileObj, posix_offset: bool = ...) -> None: ...
def __init__(self, s: str, posix_offset: bool = ...) -> None: ...
@classmethod
def instance(cls, name, offset) -> tzoffset: ...

class _ICalReader(Protocol):
# optional attribute:
# name: str
def read(self) -> str: ...

class tzical:
def __init__(self, fileobj: _FileObj) -> None: ...
def __init__(self, fileobj: str | _ICalReader) -> None: ...
def keys(self): ...
def get(self, tzid: Any | None = ...): ...

Expand Down