Skip to content

Commit b7235e1

Browse files
Merge branch 'main' into gc-ft
2 parents e359f93 + 71290a6 commit b7235e1

File tree

9 files changed

+508
-203
lines changed

9 files changed

+508
-203
lines changed

Doc/library/copy.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ and only supports named tuples created by :func:`~collections.namedtuple`,
122122
This method should create a new object of the same type,
123123
replacing fields with values from *changes*.
124124

125+
.. versionadded:: 3.13
126+
125127

126128
.. seealso::
127129

Include/internal/pycore_modsupport.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
2727
// Export for 'zlib' shared extension
2828
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
2929
Py_ssize_t, Py_ssize_t);
30-
#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
3130
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
32-
((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
31+
(((min) <= (nargs) && (nargs) <= (max)) \
3332
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
3433

3534
extern PyObject ** _Py_VaBuildStack(

Lib/test/test_uuid.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from test import support
1616
from test.support import import_helper
17+
from test.support.script_helper import assert_python_ok
1718

1819
py_uuid = import_helper.import_fresh_module('uuid', blocked=['_uuid'])
1920
c_uuid = import_helper.import_fresh_module('uuid', fresh=['_uuid'])
@@ -1217,10 +1218,37 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self):
12171218
class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
12181219
uuid = py_uuid
12191220

1221+
12201222
@unittest.skipUnless(c_uuid, 'requires the C _uuid module')
12211223
class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
12221224
uuid = c_uuid
12231225

1226+
def check_has_stable_libuuid_extractable_node(self):
1227+
if not self.uuid._has_stable_extractable_node:
1228+
self.skipTest("libuuid cannot deduce MAC address")
1229+
1230+
@unittest.skipUnless(os.name == 'posix', 'POSIX only')
1231+
def test_unix_getnode_from_libuuid(self):
1232+
self.check_has_stable_libuuid_extractable_node()
1233+
script = 'import uuid; print(uuid._unix_getnode())'
1234+
_, n_a, _ = assert_python_ok('-c', script)
1235+
_, n_b, _ = assert_python_ok('-c', script)
1236+
n_a, n_b = n_a.decode().strip(), n_b.decode().strip()
1237+
self.assertTrue(n_a.isdigit())
1238+
self.assertTrue(n_b.isdigit())
1239+
self.assertEqual(n_a, n_b)
1240+
1241+
@unittest.skipUnless(os.name == 'nt', 'Windows only')
1242+
def test_windows_getnode_from_libuuid(self):
1243+
self.check_has_stable_libuuid_extractable_node()
1244+
script = 'import uuid; print(uuid._windll_getnode())'
1245+
_, n_a, _ = assert_python_ok('-c', script)
1246+
_, n_b, _ = assert_python_ok('-c', script)
1247+
n_a, n_b = n_a.decode().strip(), n_b.decode().strip()
1248+
self.assertTrue(n_a.isdigit())
1249+
self.assertTrue(n_b.isdigit())
1250+
self.assertEqual(n_a, n_b)
1251+
12241252

12251253
class BaseTestInternals:
12261254
_uuid = py_uuid

Lib/uuid.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,22 +633,24 @@ def _netstat_getnode():
633633
try:
634634
import _uuid
635635
_generate_time_safe = getattr(_uuid, "generate_time_safe", None)
636+
_has_stable_extractable_node = _uuid.has_stable_extractable_node
636637
_UuidCreate = getattr(_uuid, "UuidCreate", None)
637638
except ImportError:
638639
_uuid = None
639640
_generate_time_safe = None
641+
_has_stable_extractable_node = False
640642
_UuidCreate = None
641643

642644

643645
def _unix_getnode():
644646
"""Get the hardware address on Unix using the _uuid extension module."""
645-
if _generate_time_safe:
647+
if _generate_time_safe and _has_stable_extractable_node:
646648
uuid_time, _ = _generate_time_safe()
647649
return UUID(bytes=uuid_time).node
648650

649651
def _windll_getnode():
650652
"""Get the hardware address on Windows using the _uuid extension module."""
651-
if _UuidCreate:
653+
if _UuidCreate and _has_stable_extractable_node:
652654
uuid_bytes = _UuidCreate()
653655
return UUID(bytes_le=uuid_bytes).node
654656

0 commit comments

Comments
 (0)