Skip to content

Commit

Permalink
More precise annotations of utils.timezone functions that return inst…
Browse files Browse the repository at this point in the history
…ances 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
  • Loading branch information
filiplajszczak authored and mkurnikov committed Nov 12, 2019
1 parent 7b74a69 commit e9a90eb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions django-stubs/utils/timezone.pyi
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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: ...
Expand Down

0 comments on commit e9a90eb

Please sign in to comment.