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

Avoid calling uuid._load_system_functions() on Python 3.9+. #425

Merged
merged 1 commit into from
Mar 1, 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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

* Avoid calling deprecated ``uuid._load_system_functions()`` on Python 3.9+.

Thanks to Nikita Sobolev for the ping in `CPython Issue #113308 <https://github.com/python/cpython/issues/113308>`__.

2.13.0 (2023-09-19)
-------------------

Expand Down
11 changes: 5 additions & 6 deletions src/time_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ def _stop(self) -> None:
uuid_generate_time_attr = "_generate_time_safe"
uuid_generate_time_patcher = mock.patch.object(uuid, uuid_generate_time_attr, new=None)
uuid_uuid_create_patcher = mock.patch.object(uuid, "_UuidCreate", new=None)
# We need to cause the functions to be loaded before we try patch them out,
# which is done by this internal function
uuid_idempotent_load_system_functions = (
uuid._load_system_functions # type: ignore[attr-defined]
)


class travel:
Expand All @@ -237,7 +232,11 @@ def start(self) -> Coordinates:
_time_machine.patch_if_needed()

if not coordinates_stack:
uuid_idempotent_load_system_functions()
if sys.version_info < (3, 9):
# We need to cause the functions to be loaded before we patch
# them out, which is done by this internal function before:
# https://github.com/python/cpython/pull/19948
uuid._load_system_functions()
uuid_generate_time_patcher.start()
uuid_uuid_create_patcher.start()

Expand Down
Loading