X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
gh-113308: Deprecate some internal parts of uuid module
  • Loading branch information
sobolevn committed Feb 26, 2024
commit 1b8a3ad2ce8ccaeb9c1badbbcdeb5ab964039cb5
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,11 @@ Pending Removal in Python 3.15
They will be removed in Python 3.15.
(Contributed by Victor Stinner in :gh:`105096`.)

* :mod:`uuid`: Deprecate some internal protected parts:
``_has_uuid_generate_time_safe``, ``_netbios_getnode``, ``_ipconfig_getnode``,
and ``_load_system_functions``. They will be removed in Python 3.15.
(Contributed by Nikita Sobolev in :gh:`113308`.)

Pending Removal in Python 3.16
------------------------------

Expand Down
22 changes: 18 additions & 4 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io
import os
import pickle
import re
import sys
import weakref
from unittest import mock
Expand Down Expand Up @@ -530,7 +531,11 @@ def test_uuid1(self):
@support.requires_mac_ver(10, 5)
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
def test_uuid1_safe(self):
if not self.uuid._has_uuid_generate_time_safe:
msg = re.escape("'_has_uuid_generate_time_safe' is deprecated and "
"slated for removal in Python 3.15")
with self.assertWarnsRegex(DeprecationWarning, msg):
has_uuid_generate_time_safe = self.uuid._has_uuid_generate_time_safe
if not has_uuid_generate_time_safe:
self.skipTest('requires uuid_generate_time_safe(3)')

u = self.uuid.uuid1()
Expand All @@ -546,7 +551,6 @@ def mock_generate_time_safe(self, safe_value):
"""
if os.name != 'posix':
self.skipTest('POSIX-only test')
self.uuid._load_system_functions()
f = self.uuid._generate_time_safe
if f is None:
self.skipTest('need uuid._generate_time_safe')
Expand Down Expand Up @@ -581,7 +585,17 @@ def test_uuid1_bogus_return_value(self):
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown)

def test_uuid1_time(self):
with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
@contextlib.contextmanager
def patch_has_uuid_generate_time_safe(value):
msg = re.escape("'_has_uuid_generate_time_safe' is deprecated and "
"slated for removal in Python 3.15")
with self.assertWarnsRegex(DeprecationWarning, msg):
with mock.patch.object(
self.uuid, '_has_uuid_generate_time_safe', value,
) as patched:
yield patched

with patch_has_uuid_generate_time_safe(False), \
mock.patch.object(self.uuid, '_generate_time_safe', None), \
mock.patch.object(self.uuid, '_last_timestamp', None), \
mock.patch.object(self.uuid, 'getnode', return_value=93328246233727), \
Expand All @@ -590,7 +604,7 @@ def test_uuid1_time(self):
u = self.uuid.uuid1()
self.assertEqual(u, self.uuid.UUID('a7a55b92-01fc-11e9-94c5-54e1acf6da7f'))

with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
with patch_has_uuid_generate_time_safe(False), \
mock.patch.object(self.uuid, '_generate_time_safe', None), \
mock.patch.object(self.uuid, '_last_timestamp', None), \
mock.patch('time.time_ns', return_value=1545052026752910643):
Expand Down
19 changes: 17 additions & 2 deletions Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import os
import sys
import warnings

from enum import Enum, _simple_enum

Expand Down Expand Up @@ -566,11 +567,13 @@ def _netstat_getnode():

def _ipconfig_getnode():
"""[DEPRECATED] Get the hardware address on Windows."""
warnings._deprecated("_ipconfig_getnode", remove=(3, 15))
# bpo-40501: UuidCreateSequential() is now the only supported approach
return _windll_getnode()

def _netbios_getnode():
"""[DEPRECATED] Get the hardware address on Windows."""
warnings._deprecated("_netbios_getnode", remove=(3, 15))
# bpo-40501: UuidCreateSequential() is now the only supported approach
return _windll_getnode()

Expand All @@ -580,16 +583,28 @@ def _netbios_getnode():
import _uuid
_generate_time_safe = getattr(_uuid, "generate_time_safe", None)
_UuidCreate = getattr(_uuid, "UuidCreate", None)
_has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe
except ImportError:
_uuid = None
_generate_time_safe = None
_UuidCreate = None
_has_uuid_generate_time_safe = None


def __getattr__(attr):
if attr == "_has_uuid_generate_time_safe":
try:
import _uuid
except ImportError:
_has_uuid_generate_time_safe = None
else:
_has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe
warnings._deprecated("_has_uuid_generate_time_safe", remove=(3, 15))
return _has_uuid_generate_time_safe
raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")


def _load_system_functions():
"""[DEPRECATED] Platform-specific functions loaded at import time"""
warnings._deprecated("_load_system_functions", remove=(3, 15))


def _unix_getnode():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:mod:`uuid`: Deprecate some internal protected parts:
``_has_uuid_generate_time_safe``, ``_netbios_getnode``,
``_ipconfig_getnode``, and ``_load_system_functions``. They will be removed
in Python 3.15.
X Tutup