mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 12:14:28 +08:00
More precise annotations of utils.timezone functions that return instances of tzinfo subclasses. (#209)
* fix annotations of utils.timezone * use intermediary tzinfo subclass exposed in pytz typeshed * fix annotations of get_fixed_timezone as it returns datetime.timezone in Django 2.2 * add explanatory comment to get_current_timezone annotations * black utils.timezone.pyi
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import types
|
||||
from contextlib import ContextDecorator
|
||||
from datetime import date, datetime as datetime, time, timedelta as timedelta, tzinfo as tzinfo
|
||||
from datetime import date, datetime as datetime, time, timedelta as timedelta, tzinfo as tzinfo, timezone
|
||||
from typing import Optional, Union, Type
|
||||
|
||||
from pytz import BaseTzInfo
|
||||
|
||||
_AnyTime = Union[time, datetime]
|
||||
|
||||
class UTC(tzinfo):
|
||||
@@ -30,10 +32,14 @@ class LocalTimezone(ReferenceLocalTimezone):
|
||||
|
||||
utc: UTC = ...
|
||||
|
||||
def get_fixed_timezone(offset: Union[timedelta, int]) -> tzinfo: ...
|
||||
def get_default_timezone() -> tzinfo: ...
|
||||
def get_fixed_timezone(offset: Union[timedelta, int]) -> timezone: ...
|
||||
def get_default_timezone() -> BaseTzInfo: ...
|
||||
def get_default_timezone_name() -> str: ...
|
||||
def get_current_timezone() -> tzinfo: ...
|
||||
|
||||
# Strictly speaking, it is possible to activate() a non-pytz timezone,
|
||||
# in which case BaseTzInfo is incorrect. However, this is unlikely,
|
||||
# so we use it anyway, to keep things ergonomic for most users.
|
||||
def get_current_timezone() -> BaseTzInfo: ...
|
||||
def get_current_timezone_name() -> str: ...
|
||||
def activate(timezone: Union[tzinfo, str]) -> None: ...
|
||||
def deactivate() -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user