Skip to content

Commit 96ead70

Browse files
committed
pythongh-113308: Deprecate some internal parts of uuid module
1 parent de0b4f9 commit 96ead70

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

Doc/whatsnew/3.13.rst

+5
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,11 @@ Pending Removal in Python 3.15
924924
They will be removed in Python 3.15.
925925
(Contributed by Victor Stinner in :gh:`105096`.)
926926

927+
* :mod:`uuid`: Deprecate some internal protected parts:
928+
``_has_uuid_generate_time_safe``, ``_netbios_getnode``, ``_ipconfig_getnode``,
929+
and ``_load_system_functions``. They will be removed in Python 3.15.
930+
(Contributed by Nikita Sobolev in :gh:`113308`.)
931+
927932
Pending Removal in Python 3.16
928933
------------------------------
929934

Lib/test/test_uuid.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,12 @@ def test_uuid1(self):
530530
@support.requires_mac_ver(10, 5)
531531
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
532532
def test_uuid1_safe(self):
533-
if not self.uuid._has_uuid_generate_time_safe:
533+
import re
534+
msg = re.escape("'_has_uuid_generate_time_safe' is deprecated and "
535+
"slated for removal in Python 3.15")
536+
with self.assertWarnsRegex(DeprecationWarning, msg):
537+
has_uuid_generate_time_safe = self.uuid._has_uuid_generate_time_safe
538+
if not has_uuid_generate_time_safe:
534539
self.skipTest('requires uuid_generate_time_safe(3)')
535540

536541
u = self.uuid.uuid1()
@@ -546,7 +551,6 @@ def mock_generate_time_safe(self, safe_value):
546551
"""
547552
if os.name != 'posix':
548553
self.skipTest('POSIX-only test')
549-
self.uuid._load_system_functions()
550554
f = self.uuid._generate_time_safe
551555
if f is None:
552556
self.skipTest('need uuid._generate_time_safe')
@@ -581,17 +585,15 @@ def test_uuid1_bogus_return_value(self):
581585
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown)
582586

583587
def test_uuid1_time(self):
584-
with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
585-
mock.patch.object(self.uuid, '_generate_time_safe', None), \
588+
with mock.patch.object(self.uuid, '_generate_time_safe', None), \
586589
mock.patch.object(self.uuid, '_last_timestamp', None), \
587590
mock.patch.object(self.uuid, 'getnode', return_value=93328246233727), \
588591
mock.patch('time.time_ns', return_value=1545052026752910643), \
589592
mock.patch('random.getrandbits', return_value=5317): # guaranteed to be random
590593
u = self.uuid.uuid1()
591594
self.assertEqual(u, self.uuid.UUID('a7a55b92-01fc-11e9-94c5-54e1acf6da7f'))
592595

593-
with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
594-
mock.patch.object(self.uuid, '_generate_time_safe', None), \
596+
with mock.patch.object(self.uuid, '_generate_time_safe', None), \
595597
mock.patch.object(self.uuid, '_last_timestamp', None), \
596598
mock.patch('time.time_ns', return_value=1545052026752910643):
597599
u = self.uuid.uuid1(node=93328246233727, clock_seq=5317)

Lib/uuid.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import os
4848
import sys
49+
import warnings
4950

5051
from enum import Enum, _simple_enum
5152

@@ -566,11 +567,13 @@ def _netstat_getnode():
566567

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

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

@@ -580,16 +583,28 @@ def _netbios_getnode():
580583
import _uuid
581584
_generate_time_safe = getattr(_uuid, "generate_time_safe", None)
582585
_UuidCreate = getattr(_uuid, "UuidCreate", None)
583-
_has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe
584586
except ImportError:
585587
_uuid = None
586588
_generate_time_safe = None
587589
_UuidCreate = None
588-
_has_uuid_generate_time_safe = None
590+
591+
592+
def __getattr__(attr):
593+
if attr == "_has_uuid_generate_time_safe":
594+
try:
595+
import _uuid
596+
except ImportError:
597+
_has_uuid_generate_time_safe = None
598+
else:
599+
_has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe
600+
warnings._deprecated("_has_uuid_generate_time_safe", remove=(3, 15))
601+
return _has_uuid_generate_time_safe
602+
raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
589603

590604

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

594609

595610
def _unix_getnode():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:mod:`uuid`: Deprecate some internal protected parts:
2+
``_has_uuid_generate_time_safe``, ``_netbios_getnode``,
3+
``_ipconfig_getnode``, and ``_load_system_functions``. They will be removed
4+
in Python 3.15.

0 commit comments

Comments
 (0)