]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for partial objects...
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 25 Jul 2024 07:11:47 +0000 (10:11 +0300)
committerGitHub <noreply@github.com>
Thu, 25 Jul 2024 07:11:47 +0000 (10:11 +0300)
Now they return False again.

Lib/inspect.py
Lib/test/test_inspect/test_inspect.py
Misc/NEWS.d/next/Library/2024-07-24-09-29-55.gh-issue-122087.FdBrWo.rst [new file with mode: 0644]

index bf979e8e63ff6530bcc52f616d65a5e51de4860c..845d55f41751a0cc13746eb7dd3d060195d5e3fe 100644 (file)
@@ -325,6 +325,11 @@ def ismethoddescriptor(object):
     if isclass(object) or ismethod(object) or isfunction(object):
         # mutual exclusion
         return False
+    if isinstance(object, functools.partial):
+        # Lie for children.  The addition of partial.__get__
+        # doesn't currently change the partial objects behaviour,
+        # not counting a warning about future changes.
+        return False
     tp = type(object)
     return (hasattr(tp, "__get__")
             and not hasattr(tp, "__set__")
index 5d0f32884d14064671d09553204b23c7f8974e66..de17558dd2d86a5c70444bde55840fa224647b59 100644 (file)
@@ -405,6 +405,8 @@ class TestPredicates(IsTestBase):
         self.assertFalse(inspect.isroutine(type))
         self.assertFalse(inspect.isroutine(int))
         self.assertFalse(inspect.isroutine(type('some_class', (), {})))
+        # partial
+        self.assertFalse(inspect.isroutine(functools.partial(mod.spam)))
 
     def test_isclass(self):
         self.istest(inspect.isclass, 'mod.StupidGit')
@@ -1906,6 +1908,7 @@ class TestIsMethodDescriptor(unittest.TestCase):
         self.assertFalse(inspect.ismethoddescriptor(Owner.static_method))
         self.assertFalse(inspect.ismethoddescriptor(function))
         self.assertFalse(inspect.ismethoddescriptor(a_lambda))
+        self.assertFalse(inspect.ismethoddescriptor(functools.partial(function)))
 
     def test_descriptor_being_a_class(self):
         class MethodDescriptorMeta(type):
diff --git a/Misc/NEWS.d/next/Library/2024-07-24-09-29-55.gh-issue-122087.FdBrWo.rst b/Misc/NEWS.d/next/Library/2024-07-24-09-29-55.gh-issue-122087.FdBrWo.rst
new file mode 100644 (file)
index 0000000..0e77741
--- /dev/null
@@ -0,0 +1,2 @@
+Restore :func:`inspect.ismethoddescriptor` and :func:`inspect.isroutine`
+returning ``False`` for :class:`functools.partial` objects.