https://github.com/python/cpython/commit/891465fc7a6cf096d5d58db70532e2f3809b1c24
commit: 891465fc7a6cf096d5d58db70532e2f3809b1c24
branch: main
author: Adorilson Bezerra <adoril...@gmail.com>
committer: picnixz <10796600+picn...@users.noreply.github.com>
date: 2025-04-12T12:02:43Z
summary:

gh-58211: Add tests for  the `__self__` attribute of builtins functions 
(#113575)

---------

Co-authored-by: Victor Stinner <vstin...@python.org>
Co-authored-by: Alex Waygood <alex.wayg...@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picn...@users.noreply.github.com>
Co-authored-by: Sergey B Kirpichev <skirpic...@gmail.com>
Co-authored-by: Serhiy Storchaka <storch...@gmail.com>

files:
M Lib/test/test_funcattrs.py

diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index d919d62613ea7c..375f456dfde834 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -3,6 +3,7 @@
 import typing
 import unittest
 import warnings
+from test import support
 
 
 def global_function():
@@ -478,6 +479,33 @@ def test_builtin__qualname__(self):
         self.assertEqual([1, 2, 3].append.__qualname__, 'list.append')
         self.assertEqual({'foo': 'bar'}.pop.__qualname__, 'dict.pop')
 
+    @support.cpython_only
+    def test_builtin__self__(self):
+        # See https://github.com/python/cpython/issues/58211.
+        import builtins
+        import time
+
+        # builtin function:
+        self.assertIs(len.__self__, builtins)
+        self.assertIs(time.sleep.__self__, time)
+
+        # builtin classmethod:
+        self.assertIs(dict.fromkeys.__self__, dict)
+        self.assertIs(float.__getformat__.__self__, float)
+
+        # builtin staticmethod:
+        self.assertIsNone(str.maketrans.__self__)
+        self.assertIsNone(bytes.maketrans.__self__)
+
+        # builtin bound instance method:
+        l = [1, 2, 3]
+        self.assertIs(l.append.__self__, l)
+
+        d = {'foo': 'bar'}
+        self.assertEqual(d.pop.__self__, d)
+
+        self.assertIsNone(None.__repr__.__self__)
+
 
 if __name__ == "__main__":
     unittest.main()

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to