Skip to content
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

feat(speedups): use ciso8601 for deserializing datetimes from the gateway #658

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion changelog/648.doc.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Update :attr:`InteractionReference.name` description, now includes group and subcommand.
Update :attr:`InteractionReference.name` description, now includes group and subcommand.
38 changes: 34 additions & 4 deletions disnake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
else:
HAS_ORJSON = True

try:
import ciso8601
except ModuleNotFoundError:
HAS_CISO8601 = False
else:
HAS_CISO8601 = True

__all__ = (
"oauth_url",
Expand Down Expand Up @@ -226,26 +232,50 @@ def count(self, value: Any) -> int:


@overload
def parse_time(timestamp: None) -> None:
def _parse_time_ciso8601(timestamp: None) -> None:
...


@overload
def parse_time(timestamp: str) -> datetime.datetime:
def _parse_time_ciso8601(timestamp: str) -> datetime.datetime:
...


@overload
def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]:
def _parse_time_ciso8601(timestamp: Optional[str]) -> Optional[datetime.datetime]:
...


def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]:
def _parse_time_ciso8601(timestamp: Optional[str]) -> Optional[datetime.datetime]:
if timestamp:
return ciso8601.parse_datetime(timestamp)
return None


@overload
def _parse_time_std(timestamp: None) -> None:
...


@overload
def _parse_time_std(timestamp: str) -> datetime.datetime:
...


@overload
def _parse_time_std(timestamp: Optional[str]) -> Optional[datetime.datetime]:
...


def _parse_time_std(timestamp: Optional[str]) -> Optional[datetime.datetime]:
if timestamp:
return datetime.datetime.fromisoformat(timestamp)
return None


parse_time = _parse_time_ciso8601 if HAS_CISO8601 else _parse_time_std


@overload
def isoformat_utc(dt: datetime.datetime) -> str:
...
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements_speed.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
orjson~=3.6
ciso8601==2.2
# taken from aiohttp[speedups]
aiodns>=1.1
Brotli
Expand Down