1

Bound methods for both builtin and pure heap-types have a __self__ attribute from which the method's owner class can be retrieved. But unbound methods attached to heap types that only inherit from object do not have the __objclass__ attribute.

Because methods clearly know which class invokes them when called, there has to be a way to see which class it belongs to, right?

And I hope that I'm right calling classes like str, list, and _collections.deque "builtin" classes and classes defined completely in Python "heap types", correct me if I'm wrong.

bup
  • 103
  • 5
  • The `__self__` attribute can be used to find the owner _object_, not _class_. And what's an "owner class" anyway? The class where the method was defined? – Aran-Fey Jun 11 '17 at 20:17
  • I have never heard "heap types" used the way you describe in Python. User-defined classes are just user-defined classes. That said, in Python 3, unbound methods were removed, so there is no real way to get the class from an "unbound method" because the unbound method isn't a method, it's just a plain function. You would have to manually search the class hierarchy for the method. I think there is a duplicate question about this but I can't find it right now. – BrenBarn Jun 11 '17 at 20:25
  • 1
    Yes, the class where it was defined Rawing. And I'm pretty sure classes defined in python are called heap types as I've seen errors mentioning heap types and the 10th bit in `obj.__flags__` is `Py_TPFLAGS_HEAPTYPE`, which will only be set for classes defined in Python. – bup Jun 11 '17 at 20:29
  • @bup: The term "heap type" is used in some internal language relating to the C implementation of Python, but the ordinary term for "user-defined classes" is. . . "user-defined classes" (or just "Python classes"). – BrenBarn Jun 11 '17 at 20:32

0 Answers0