mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
dateutil.tz.tz: Replace IO with protocols (#7717)
This commit is contained in:
@@ -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
|
||||
@@ -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: ...
|
||||
@@ -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 = ...): ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user