Skip to content

gh-137754: Fix import of zoneinfo if _datetime is not available #137845

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 16, 2025

Both modules should use the Python implementation in that case.

Both modules should use the Python implementation in that case.
@serhiy-storchaka serhiy-storchaka force-pushed the import-zoneinfo-pydatetime branch from 33ebff4 to 312a09c Compare August 17, 2025 06:09
@AA-Turner
Copy link
Member

Windows is failing as it can't find Europe/Paris, maybe the test should be skipped:

Traceback (most recent call last):
  File "D:\a\cpython\cpython\Lib\zoneinfo\_common.py", line 12, in load_tzdata
    path = resources.files(package_name).joinpath(resource_name)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "D:\a\cpython\cpython\Lib\importlib\resources\_common.py", line 46, in wrapper
    return func(anchor)
  File "D:\a\cpython\cpython\Lib\importlib\resources\_common.py", line 56, in files
    return from_package(resolve(anchor))
                        ~~~~~~~^^^^^^^^
  File "D:\a\cpython\cpython\Lib\functools.py", line 982, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "D:\a\cpython\cpython\Lib\importlib\resources\_common.py", line 82, in _
    return importlib.import_module(cand)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "D:\a\cpython\cpython\Lib\importlib\__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1398, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1314, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1398, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1314, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1398, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1335, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tzdata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
    tzinfo = zoneinfo.ZoneInfo('Europe/Paris')
  File "D:\a\cpython\cpython\Lib\zoneinfo\_zoneinfo.py", line 43, in __new__
    instance = cls._weak_cache.setdefault(key, cls._new_instance(key))
                                               ~~~~~~~~~~~~~~~~~^^^^^
  File "D:\a\cpython\cpython\Lib\zoneinfo\_zoneinfo.py", line 70, in _new_instance
    file_obj = _common.load_tzdata(key)
  File "D:\a\cpython\cpython\Lib\zoneinfo\_common.py", line 29, in load_tzdata
    raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Europe/Paris'

@serhiy-storchaka serhiy-storchaka merged commit 6620ef0 into python:main Aug 23, 2025
44 checks passed
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the import-zoneinfo-pydatetime branch August 23, 2025 09:12
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 23, 2025
…pythonGH-137845)

Both modules should use the Python implementation in that case.
(cherry picked from commit 6620ef0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 23, 2025
…pythonGH-137845)

Both modules should use the Python implementation in that case.
(cherry picked from commit 6620ef0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Aug 23, 2025

GH-138084 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Aug 23, 2025
@bedevere-app
Copy link

bedevere-app bot commented Aug 23, 2025

GH-138085 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 23, 2025
serhiy-storchaka added a commit that referenced this pull request Aug 23, 2025
GH-137845) (GH-138085)

Both modules should use the Python implementation in that case.
(cherry picked from commit 6620ef0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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

Successfully merging this pull request may close these issues.

3 participants