Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ def test_isroutine(self):
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')
Expand Down Expand Up @@ -1906,6 +1908,7 @@ def function():
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Restore :func:`inspect.ismethoddescriptor` and :func:`inspect.isroutine`
returning ``False`` for :class:`functools.partial` objects.