mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] gh-58211: Add tests for the __self__
attribute of builtins functions (GH-113575) (#132437)
gh-58211: Add tests for the `__self__` attribute of builtins functions (GH-113575)
---------
(cherry picked from commit 891465fc7a
)
Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
17b61394ee
commit
70c4bd63d4
1 changed files with 28 additions and 0 deletions
|
@ -3,6 +3,7 @@ import types
|
|||
import typing
|
||||
import unittest
|
||||
import warnings
|
||||
from test import support
|
||||
|
||||
|
||||
def global_function():
|
||||
|
@ -478,6 +479,33 @@ class BuiltinFunctionPropertiesTest(unittest.TestCase):
|
|||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue