Skip to content

Commit

Permalink
Avoid calling uuid._load_system_functions() on Python 3.9+. (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Mar 1, 2024
1 parent 4bd96a2 commit 2eda5ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit 2eda5ad

Please sign in to comment.