Skip to content

Commit 891465f

Browse files
adorilsonvstinnerAlexWaygoodpicnixzskirpichev
authored
gh-58211: Add tests for the __self__ attribute of builtins functions (#113575)
--------- Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 517e96b commit 891465f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Lib/test/test_funcattrs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import typing
44
import unittest
55
import warnings
6+
from test import support
67

78

89
def global_function():
@@ -478,6 +479,33 @@ def test_builtin__qualname__(self):
478479
self.assertEqual([1, 2, 3].append.__qualname__, 'list.append')
479480
self.assertEqual({'foo': 'bar'}.pop.__qualname__, 'dict.pop')
480481

482+
@support.cpython_only
483+
def test_builtin__self__(self):
484+
# See https://github.com/python/cpython/issues/58211.
485+
import builtins
486+
import time
487+
488+
# builtin function:
489+
self.assertIs(len.__self__, builtins)
490+
self.assertIs(time.sleep.__self__, time)
491+
492+
# builtin classmethod:
493+
self.assertIs(dict.fromkeys.__self__, dict)
494+
self.assertIs(float.__getformat__.__self__, float)
495+
496+
# builtin staticmethod:
497+
self.assertIsNone(str.maketrans.__self__)
498+
self.assertIsNone(bytes.maketrans.__self__)
499+
500+
# builtin bound instance method:
501+
l = [1, 2, 3]
502+
self.assertIs(l.append.__self__, l)
503+
504+
d = {'foo': 'bar'}
505+
self.assertEqual(d.pop.__self__, d)
506+
507+
self.assertIsNone(None.__repr__.__self__)
508+
481509

482510
if __name__ == "__main__":
483511
unittest.main()

0 commit comments

Comments
 (0)