Skip to content

More precise annotations of utils.timezone functions that return instances of tzinfo subclasses. #209

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 5 commits into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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