]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97966: Restore prior expectation that uname_result._fields and ._asdict would...
authorJason R. Coombs <jaraco@jaraco.com>
Sat, 26 Nov 2022 13:28:49 +0000 (08:28 -0500)
committerGitHub <noreply@github.com>
Sat, 26 Nov 2022 13:28:49 +0000 (08:28 -0500)
Lib/platform.py
Lib/test/test_platform.py
Misc/NEWS.d/next/Library/2022-10-16-18-52-00.gh-issue-97966.humlhz.rst [new file with mode: 0644]

index 9f5b317287530bdb792cdd0985c704ece9885eb3..6745321e31c279e458b279bb0980cfb3ed9cb33f 100755 (executable)
@@ -847,6 +847,8 @@ class uname_result(
     except when needed.
     """
 
+    _fields = ('system', 'node', 'release', 'version', 'machine', 'processor')
+
     @functools.cached_property
     def processor(self):
         return _unknown_as_blank(_Processor.get())
@@ -860,7 +862,7 @@ class uname_result(
     @classmethod
     def _make(cls, iterable):
         # override factory to affect length check
-        num_fields = len(cls._fields)
+        num_fields = len(cls._fields) - 1
         result = cls.__new__(cls, *iterable)
         if len(result) != num_fields + 1:
             msg = f'Expected {num_fields} arguments, got {len(result)}'
@@ -874,7 +876,7 @@ class uname_result(
         return len(tuple(iter(self)))
 
     def __reduce__(self):
-        return uname_result, tuple(self)[:len(self._fields)]
+        return uname_result, tuple(self)[:len(self._fields) - 1]
 
 
 _uname_cache = None
index 9c03a89fd57d07491458484711039100f7ba80a1..3992faf8e5cd5bf0002a13952938e9c6db330149 100644 (file)
@@ -277,6 +277,14 @@ class PlatformTest(unittest.TestCase):
         self.assertEqual(res[:], expected)
         self.assertEqual(res[:5], expected[:5])
 
+    def test_uname_fields(self):
+        self.assertIn('processor', platform.uname()._fields)
+
+    def test_uname_asdict(self):
+        res = platform.uname()._asdict()
+        self.assertEqual(len(res), 6)
+        self.assertIn('processor', res)
+
     @unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used")
     @support.requires_subprocess()
     def test_uname_processor(self):
diff --git a/Misc/NEWS.d/next/Library/2022-10-16-18-52-00.gh-issue-97966.humlhz.rst b/Misc/NEWS.d/next/Library/2022-10-16-18-52-00.gh-issue-97966.humlhz.rst
new file mode 100644 (file)
index 0000000..b725465
--- /dev/null
@@ -0,0 +1,2 @@
+On ``uname_result``, restored expectation that ``_fields`` and ``_asdict``
+would include all six properties including ``processor``.