FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-58211: Add tests for __self__ attribute of builtins functions by adorilson · Pull Request #113575 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 28 additions & 0 deletions Lib/test/test_funcattrs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import typing
import unittest
import warnings
from test import support


def global_function():
Expand Down Expand Up @@ -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__)

Comment thread
serhiy-storchaka marked this conversation as resolved.

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

Back | FazBrowse Home | New Git URL