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

gh-113308: Remove some internal parts of uuid module #115934

Merged
merged 9 commits into from
Mar 14, 2024
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,11 @@ Pending Removal in Python 3.15
in Python 3.15. To create a TypedDict class with 0 fields, use ``class
TD(TypedDict): pass`` or ``TD = TypedDict("TD", {})``.

* :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`.)

* :mod:`wave`: Deprecate the ``getmark()``, ``setmark()`` and ``getmarkers()``
methods of the :class:`wave.Wave_read` and :class:`wave.Wave_write` classes.
They will be removed in Python 3.15.
Expand Down
26 changes: 22 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,10 @@ def mock_generate_time_safe(self, safe_value):
"""
if os.name != 'posix':
self.skipTest('POSIX-only test')
self.uuid._load_system_functions()
msg = re.escape("'_load_system_functions' is deprecated and "
"slated for removal in Python 3.15")
with self.assertWarnsRegex(DeprecationWarning, msg):
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 +589,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 +608,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
16 changes: 14 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,25 @@ 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":
warnings._deprecated("_has_uuid_generate_time_safe", remove=(3, 15))
if _uuid is None:
return None
else:
return _uuid.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.
Loading