encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
27.83k stars 6.76k forks source link

RFE: use `zoneinfo` instead of `pytz` #9418

Closed wuch-g2v closed 1 month ago

wuch-g2v commented 1 month ago

Switch to standard zoneinfo module. Below may help https://github.com/pydantic/pydantic-core/commit/fd262933

[wuch@pers-jacek django-rest-framework-3.15.1]$ grep -r pytz
docs/api-guide/fields.md:* `default_timezone` - A `tzinfo` subclass (`zoneinfo` or `pytz`) representing the timezone. If not specified and the `USE_TZ` setting is enabled, this defaults to the [current timezone][django-current-timezone]. If `USE_TZ` is disabled, then datetime objects will be naive.
docs/community/3.15-announcement.md:Dependency on pytz has been removed and deprecation warnings have been added, Django will provide ZoneInfo instances as long as USE_DEPRECATED_PYTZ is not enabled. More info on the migration can be found [in this guide](https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html).
docs/community/release-notes.md:* Remove dependency on `pytz` [[#8984](https://github.com/encode/django-rest-framework/pull/8984)]
requirements.txt:# just Django and pytz, but for the purposes of development
rest_framework/utils/timezone.py:    """Check if a datetime exists. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
rest_framework/utils/timezone.py:    """Check whether a datetime is ambiguous. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
rest_framework/fields.py:    import pytz
rest_framework/fields.py:    pytz = None
rest_framework/fields.py:                if pytz and isinstance(e, pytz.exceptions.InvalidTimeError):
setup.cfg:known_third_party=pytest,_pytest,django,pytz,uritemplate
tests/test_fields.py:    import pytz
tests/test_fields.py:    pytz = None
tests/test_fields.py:        Check UTC for datetime.timezone, ZoneInfo, and pytz tzinfo instances.
tests/test_fields.py:@pytest.mark.skipif(pytz is None, reason="As Django 4.0 has deprecated pytz, this test should eventually be able to get removed.")
tests/test_fields.py:    if pytz:
tests/test_fields.py:        class MockTimezone(pytz.BaseTzInfo):
tests/test_fields.py:                raise pytz.InvalidTimeError()
tomchristie commented 1 month ago

I don't think we'd act on this without a more clearly stated rationale.

If you'd like to pick up on this again, please use a design discussion as the starting point.

browniebroke commented 1 month ago

Found this existing discussion: https://github.com/encode/django-rest-framework/discussions/8562