Skip to content

5.0: Remove pytz support #1980

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 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion django-stubs/conf/global_settings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ TIME_ZONE: str

# If you set this to True, Django will use timezone-aware datetimes.
USE_TZ: bool
USE_DEPRECATED_PYTZ: bool

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
Expand Down
2 changes: 0 additions & 2 deletions django-stubs/db/backends/base/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ _ExecuteWrapper: TypeAlias = Callable[
[Callable[[str, Any, bool, dict[str, Any]], Any], str, Any, bool, dict[str, Any]], Any
]

def timezone_constructor(tzname: str) -> tzinfo: ...

class BaseDatabaseWrapper:
data_types: dict[str, str]
data_types_suffix: dict[str, str]
Expand Down
5 changes: 2 additions & 3 deletions django-stubs/templatetags/tz.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from datetime import datetime
from datetime import datetime, tzinfo
from typing import Any

from django.template import Node
from django.template.base import FilterExpression, NodeList, Parser, Token
from django.utils.timezone import _TzInfoT

register: Any

class datetimeobject(datetime): ...

def localtime(value: datetime | str | None) -> Any: ...
def utc(value: datetime | str | None) -> Any: ...
def do_timezone(value: datetime | str | None, arg: _TzInfoT | str | None) -> Any: ...
def do_timezone(value: datetime | str | None, arg: tzinfo | str | None) -> Any: ...

class LocalTimeNode(Node):
nodelist: NodeList
Expand Down
8 changes: 3 additions & 5 deletions django-stubs/utils/dateformat.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from datetime import date
from datetime import date, tzinfo
from datetime import datetime as builtin_datetime
from datetime import time as builtin_time
from re import Pattern
from typing import Any, Literal

from django.utils.timezone import _TzInfoT

re_formatchars: Pattern[str]
re_escaped: Pattern[str]

Expand All @@ -14,7 +12,7 @@ class Formatter:

class TimeFormat(Formatter):
data: builtin_datetime | builtin_time
timezone: _TzInfoT | None
timezone: tzinfo | None
def __init__(self, obj: builtin_datetime | builtin_time) -> None: ...
def a(self) -> str: ...
def A(self) -> str: ...
Expand All @@ -34,7 +32,7 @@ class TimeFormat(Formatter):

class DateFormat(TimeFormat):
data: builtin_datetime | date | builtin_time # type: ignore[assignment]
timezone: _TzInfoT | None
timezone: tzinfo | None
year_days: Any
def __init__(self, obj: builtin_datetime | builtin_time | date) -> None: ...
def b(self) -> str: ...
Expand Down
33 changes: 11 additions & 22 deletions django-stubs/utils/timezone.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@ from datetime import date, datetime, time, timedelta, timezone, tzinfo
from types import TracebackType
from typing import Any, Literal, overload

import pytz
from pytz import BaseTzInfo
from typing_extensions import TypeAlias, TypeGuard

_PytzTzInfoT: TypeAlias = pytz.tzinfo.BaseTzInfo | pytz._FixedOffset

_TzInfoT: TypeAlias = _PytzTzInfoT | tzinfo
import zoneinfo

utc: Any

def get_fixed_timezone(offset: timedelta | int) -> timezone: ...
def get_default_timezone() -> BaseTzInfo: ...
def get_default_timezone() -> zoneinfo.ZoneInfo: ...
def get_default_timezone_name() -> str: ...

# 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() -> zoneinfo.ZoneInfo: ...
def get_current_timezone_name() -> str: ...
def activate(timezone: _TzInfoT | str) -> None: ...
def activate(timezone: tzinfo | str) -> None: ...
def deactivate() -> None: ...

class override(ContextDecorator):
timezone: str | _TzInfoT | None
old_timezone: _TzInfoT | None
def __init__(self, timezone: str | _TzInfoT | None) -> None: ...
timezone: str | tzinfo | None
old_timezone: tzinfo | None
def __init__(self, timezone: str | tzinfo | None) -> None: ...
def __enter__(self) -> None: ...
def __exit__(
self,
Expand All @@ -37,8 +27,8 @@ class override(ContextDecorator):
exc_tb: TracebackType | None,
) -> None: ...

def localtime(value: datetime | None = ..., timezone: _TzInfoT | None = ...) -> datetime: ...
def localdate(value: datetime | None = ..., timezone: _TzInfoT | None = ...) -> date: ...
def localtime(value: datetime | None = ..., timezone: tzinfo | None = ...) -> datetime: ...
def localdate(value: datetime | None = ..., timezone: tzinfo | None = ...) -> date: ...
def now() -> datetime: ...
@overload
def is_aware(value: time) -> Literal[False]: ...
Expand All @@ -48,6 +38,5 @@ def is_aware(value: datetime) -> bool: ...
def is_naive(value: time) -> Literal[True]: ...
@overload
def is_naive(value: datetime) -> bool: ...
def make_aware(value: datetime, timezone: _TzInfoT | None = ..., is_dst: bool | None = ...) -> datetime: ...
def make_naive(value: datetime, timezone: _TzInfoT | None = ...) -> datetime: ...
def _is_pytz_zone(tz: _TzInfoT) -> TypeGuard[_PytzTzInfoT]: ...
def make_aware(value: datetime, timezone: tzinfo | None = ..., is_dst: bool | None = ...) -> datetime: ...
def make_naive(value: datetime, timezone: tzinfo | None = ...) -> datetime: ...
2 changes: 0 additions & 2 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
django.conf.FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG
django.conf.global_settings.CSRF_COOKIE_MASKED
django.conf.global_settings.FORMS_URLFIELD_ASSUME_HTTPS
django.conf.global_settings.USE_DEPRECATED_PYTZ
django.conf.global_settings.USE_L10N
django.contrib.admin.AdminSite.get_model_admin
django.contrib.admin.AllValuesFieldListFilter.get_facet_counts
Expand Down Expand Up @@ -109,7 +108,6 @@ django.core.handlers.asgi.get_script_prefix
django.core.management.commands.inspectdb.Command.normalize_table_name
django.core.management.commands.optimizemigration
django.core.serializers.base.PickleSerializer
django.db.backends.base.base.timezone_constructor
django.db.backends.base.features.BaseDatabaseFeatures.delete_can_self_reference_subquery
django.db.backends.base.features.BaseDatabaseFeatures.insert_test_table_with_defaults
django.db.backends.base.features.BaseDatabaseFeatures.supports_default_keyword_in_bulk_insert
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def find_stub_files(name: str) -> List[str]:
"tomli; python_version < '3.11'",
# Types:
"typing-extensions",
"types-pytz",
"types-PyYAML",
]

Expand Down