From 2732a66e81dd19733ab0ab4160f69dabfca866d2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 20 Mar 2016 11:15:51 -0300 Subject: [PATCH] Improve name_that_thing to handle instance methods --- channels/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/channels/utils.py b/channels/utils.py index 770f23e..e8f060e 100644 --- a/channels/utils.py +++ b/channels/utils.py @@ -5,12 +5,17 @@ def name_that_thing(thing): """ Returns either the function/class path or just the object's repr """ + # Instance method + if hasattr(thing, "im_class"): + return name_that_thing(thing.im_class) + "." + thing.im_func.func_name + # Other named thing if hasattr(thing, "__name__"): if hasattr(thing, "__class__") and not isinstance(thing, types.FunctionType): if thing.__class__ is not type: return name_that_thing(thing.__class__) if hasattr(thing, "__module__"): return "%s.%s" % (thing.__module__, thing.__name__) + # Generic instance of a class if hasattr(thing, "__class__"): return name_that_thing(thing.__class__) return repr(thing)