8000 [3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for pa… · python/cpython@4e77165 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e77165

Browse files
[3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for partial objects (GH-122218)
Now they return False again.
1 parent 716c677 commit 4e77165

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/inspect.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ def ismethoddescriptor(object):
325325
if isclass(object) or ismethod(object) or isfunction(object):
326326
# mutual exclusion
327327
return False
328+
if isinstance(object, functools.partial):
329+
# Lie for children. The addition of partial.__get__
330+
# doesn't currently change the partial objects behaviour,
331+
# not counting a warning about future changes.
332+
return False
328333
tp = type(object)
329334
return (hasattr(tp, "__get__")
330335
and not hasattr(tp, "__set__")

Lib/test/test_inspect/test_inspect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ def test_isroutine(self):
405405
self.assertFalse(inspect.isroutine(type))
406406
self.assertFalse(inspect.isroutine(int))
407407
self.assertFalse(inspect.isroutine(type('some_class', (), {})))
408+
# partial
409+
self.assertFalse(inspect.isroutine(functools.partial(mod.spam)))
408410

409411
def test_isclass(self):
410412
self.istest(inspect.isclass, 'mod.StupidGit')
@@ -1906,6 +1908,7 @@ def function():
19061908
self.assertFalse(inspect.ismethoddescriptor(Owner.static_method))
19071909
self.assertFalse(inspect.ismethoddescriptor(function))
19081910
self.assertFalse(inspect.ismethoddescriptor(a_lambda))
1911+
self.assertFalse(inspect.ismethoddescriptor(functools.partial(function)))
19091912

19101913
def test_descriptor_being_a_class(self):
19111914
class MethodDescriptorMeta(type):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Restore :func:`inspect.ismethoddescriptor` and :func:`inspect.isroutine`
2+
returning ``False`` for :class:`functools.partial` objects.

0 commit comments

Comments
 (0)
0