summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorFurkan Onder <furkanonder@protonmail.com>2024-10-30 18:20:02 (GMT)
committerGitHub <noreply@github.com>2024-10-30 18:20:02 (GMT)
commit4f826214b30ad50365f45bf07e4a02f34f897ab5 (patch)
treea00f9beeebfb9c6ffa09ba8c6adfa189c1be6c9b /Lib/test
parent6f512c603465ff3e51e07cb7e1d36b4e5e88905d (diff)
downloadcpython-4f826214b30ad50365f45bf07e4a02f34f897ab5.zip
cpython-4f826214b30ad50365f45bf07e4a02f34f897ab5.tar.gz
cpython-4f826214b30ad50365f45bf07e4a02f34f897ab5.tar.bz2
gh-60712: Include the "object" type in the lists of documented types (GH-103036)
* add test for the predefined object's attributes * Include the "object" type in the lists of documented types * remove 'or' from augment tuple * 📜🤖 Added by blurb_it. * Add cross-reference to news Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * Fix format for the function parameter Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * Add space Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * add reference for the 'object' Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * add reference for NotImplemented Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * Change ref:`string <textseq>` as class:`str` Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * remove hyphen from `newly-created` * Update Doc/reference/datamodel.rst 'dictionaries' to 'dict' Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> * Update predefined attribute types in testPredefinedAttrs * Change `universal type` as `top type` * Don't mention about the top type * Update the description of richcmpfuncs * Update Doc/library/stdtypes.rst Co-authored-by: Éric <merwok@netwok.org> * Revert: Hierarchy Section in Data Model Documentation * Revert to original explanations of __new__ and __init__ methods in datamodel.rst for improved clarity. * Update Doc/reference/datamodel.rst Co-authored-by: Éric <merwok@netwok.org> * Remove blank line Co-authored-by: Éric <merwok@netwok.org> * Use ref:`str <textseq>` instead of :class:`str Co-authored-by: Éric <merwok@netwok.org> * Revert changes the description of Other Built-in Types in stdtypes.rst * Update Doc/reference/datamodel.rst Co-authored-by: Éric <merwok@netwok.org> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index b88c4d1..7720cf1 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -503,6 +503,56 @@ class ClassTests(unittest.TestCase):
self.assertRaises(TypeError, hash, C2())
+ def testPredefinedAttrs(self):
+ o = object()
+
+ class Custom:
+ pass
+
+ c = Custom()
+
+ methods = (
+ '__class__', '__delattr__', '__dir__', '__eq__', '__format__',
+ '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__',
+ '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__',
+ '__new__', '__reduce__', '__reduce_ex__', '__repr__',
+ '__setattr__', '__sizeof__', '__str__', '__subclasshook__'
+ )
+ for name in methods:
+ with self.subTest(name):
+ self.assertTrue(callable(getattr(object, name, None)))
+ self.assertTrue(callable(getattr(o, name, None)))
+ self.assertTrue(callable(getattr(Custom, name, None)))
+ self.assertTrue(callable(getattr(c, name, None)))
+
+ not_defined = [
+ '__abs__', '__aenter__', '__aexit__', '__aiter__', '__anext__',
+ '__await__', '__bool__', '__bytes__', '__ceil__',
+ '__complex__', '__contains__', '__del__', '__delete__',
+ '__delitem__', '__divmod__', '__enter__', '__exit__',
+ '__float__', '__floor__', '__get__', '__getattr__', '__getitem__',
+ '__index__', '__int__', '__invert__', '__iter__', '__len__',
+ '__length_hint__', '__missing__', '__neg__', '__next__',
+ '__objclass__', '__pos__', '__rdivmod__', '__reversed__',
+ '__round__', '__set__', '__setitem__', '__trunc__'
+ ]
+ augment = (
+ 'add', 'and', 'floordiv', 'lshift', 'matmul', 'mod', 'mul', 'pow',
+ 'rshift', 'sub', 'truediv', 'xor'
+ )
+ not_defined.extend(map("__{}__".format, augment))
+ not_defined.extend(map("__r{}__".format, augment))
+ not_defined.extend(map("__i{}__".format, augment))
+ for name in not_defined:
+ with self.subTest(name):
+ self.assertFalse(hasattr(object, name))
+ self.assertFalse(hasattr(o, name))
+ self.assertFalse(hasattr(Custom, name))
+ self.assertFalse(hasattr(c, name))
+
+ # __call__() is defined on the metaclass but not the class
+ self.assertFalse(hasattr(o, "__call__"))
+ self.assertFalse(hasattr(c, "__call__"))
def testSFBug532646(self):
# Test for SF bug 532646