Skip to content
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

RFE: use zoneinfo instead of pytz #1088

Open
kloczek opened this issue May 30, 2024 · 5 comments
Open

RFE: use zoneinfo instead of pytz #1088

kloczek opened this issue May 30, 2024 · 5 comments

Comments

@kloczek
Copy link

kloczek commented May 30, 2024

Switch to standard zoneinfo module.
Below may help pydantic/pydantic-core@fd262933

CHANGES.rst:* Dates: `pytz` is now optional; Babel will prefer it but will use `zoneinfo` when available. (:gh:`940`) - @ds-cbo
CHANGES.rst:* Note that installation requires pytz - Steve (Gadget) Barnes
CHANGES.rst:* General: Bumped version requirement on pytz - @chrisbrake (:gh:`592`)
CHANGES.rst:- added dummy version requirements for pytz so that it installs
CHANGES.rst:- depend on pytz now and wrap it nicer.  This gives us improved support
babel/dates.py:    import pytz
babel/dates.py:    pytz = None
babel/dates.py:    # Support localizing with both pytz and zoneinfo tzinfos
babel/dates.py:    if hasattr(tz, 'localize'):  # pytz
babel/dates.py:    if hasattr(tzinfo, 'zone'):  # pytz object
babel/dates.py:        if hasattr(tzinfo, 'normalize'):  # pytz
babel/dates.py:            if hasattr(tzinfo, 'normalize'):  # pytz
babel/dates.py:    returned comes from ``pytz`` or ``zoneinfo``, whichever is available.
babel/dates.py:    if pytz:
babel/dates.py:            return pytz.timezone(zone)
babel/dates.py:        except pytz.UnknownTimeZoneError as e:
babel/localtime/_helpers.py:    import pytz
babel/localtime/_helpers.py:    pytz = None
babel/localtime/_helpers.py:    """Get the tzinfo from `zoneinfo` or `pytz`
babel/localtime/_helpers.py:    if pytz:
babel/localtime/_helpers.py:            return pytz.timezone(tzenv)
babel/localtime/_helpers.py:        except pytz.UnknownTimeZoneError:
babel/localtime/_helpers.py:        if pytz:
babel/localtime/_helpers.py:            return pytz.tzfile.build_tzinfo('local', tzfile)
babel/localtime/_unix.py:    zoneinfo or pytz, over passing in the localtime file, as in the later
docs/dates.rst:Babel uses either `zoneinfo`_ or `pytz`_ for timezone support.
docs/dates.rst:If pytz is installed, it is preferred over the standard library's zoneinfo.
docs/dates.rst:You can use Babel together with ``zoneinfo`` or ``pytz`` to apply a time-zone
docs/dates.rst:.. _pytz: https://pythonhosted.org/pytz/
docs/dev.rst:Babel's timezone support relies on either ``pytz`` or ``zoneinfo``; if ``pytz``
docs/installation.rst:`zoneinfo`_ module is not available, `pytz`_  needs to be installed for
docs/installation.rst:timezone support. If `pytz`_  is installed, it is preferred over the
docs/installation.rst:.. _pytz: https://pythonhosted.org/pytz/
setup.py:        # pytz otherwise does not install on pip 1.4 or
setup.py:        # Python 3.9 and later include zoneinfo which replaces pytz
setup.py:        'pytz>=2015.7; python_version<"3.9"',
tests/conftest.py:    import pytz
tests/conftest.py:    pytz = None
tests/conftest.py:@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package")
tests/conftest.py:    if request.param == "pytz.timezone":
tests/conftest.py:        if pytz:
tests/conftest.py:            return pytz.timezone
tests/conftest.py:            pytest.skip("pytz not available")
tests/test_dates.py:@pytest.mark.parametrize("timezone_getter", ["pytz.timezone"], indirect=True)
tests/test_dates.py:def test_get_timezone_name_time_pytz(timezone_getter, tzname, params, expected):
tests/test_dates.py:    """pytz (by design) can't determine if the time is in DST or not,
tox.ini:    py{38}-pytz
tox.ini:    pytz: pytz
@jun66j5
Copy link
Contributor

jun66j5 commented May 30, 2024

Babel still supports Python 3.8 which doesn't have zoneinfo. Also pytz is optional for Python 3.9+ but Babel allows to use pytz if a user want to use pytz rather than zoneinfo. Therefore, I don't consider uses of pytz should be removed.

See setup.py:

    python_requires='>=3.8',
    packages=['babel', 'babel.messages', 'babel.localtime'],
    package_data={"babel": ["py.typed"]},
    include_package_data=True,
    install_requires=[
        # This version identifier is currently necessary as
        # pytz otherwise does not install on pip 1.4 or
        # higher.
        # Python 3.9 and later include zoneinfo which replaces pytz
        'pytz>=2015.7; python_version<"3.9"',
    ],

@kloczek
Copy link
Author

kloczek commented May 30, 2024

Oct this year 3.8 will be EOSed.
Also commit which I've mention shows example how to handle 3.8.

@akx
Copy link
Member

akx commented Jul 17, 2024

At some point, dropping support for pytz will allow us to remove compatibility code, but as said above, we don't require it for Python 3.9+, and will only prefer it if it's installed.

Is there something pytz might do better (e.g. API-wise) than zoneinfo that would still warrant keeping it around?

@kloczek
Copy link
Author

kloczek commented Jul 18, 2024

FYI Python 3.8 will be EOSed Oct this year,

@akx
Copy link
Member

akx commented Jul 18, 2024

@kloczek I am aware. Babel has traditionally supported slightly older Python versions as well due to the broad userbase :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants