diff --git a/python-package/xgboost/compat.py b/python-package/xgboost/compat.py index c0b589018caa..cea85c8c6c6c 100644 --- a/python-package/xgboost/compat.py +++ b/python-package/xgboost/compat.py @@ -20,9 +20,13 @@ def py_str(x): def lazy_isinstance(instance, module, name): - '''Use string representation to identify a type.''' - module = type(instance).__module__ == module - name = type(instance).__name__ == name + """Use string representation to identify a type.""" + + # Notice, we use .__class__ as opposed to type() in order + # to support object proxies such as weakref.proxy + cls = instance.__class__ + module = cls.__module__ == module + name = cls.__name__ == name return module and name