What is a 'slot wrapper' in python?

python

Solution

According to https://doc.sagemath.org/html/en/reference/cpython/sage/cpython/wrapperdescr.html :

A slot wrapper is installed in the dict of an extension type to access a special method implemented in C. For example, object.__init__ or Integer.__lt__. Note that slot wrappers are always unbound (there is a bound variant called method-wrapper).

So, they are actually methods which wrap over C-implemented methods of objects. Many of the magic methods and attributes in Python are implemented via slot wrappers over C objects. As most implementations of Python are written in C, this makes sense.

Problem

`object.__dict__` and other places have their hidden methods set to things like this: ``` <dictproxy {'__add__': <slot wrapper '__add__' of 'instance' objects>, '__and__': <slot wrapper '__and__' of 'instance' objects>, '__call__': <slot wrapper '__call__' of 'instance' objects>, '__cmp__': <slot wrapper '__cmp__' of 'instance' objects>, '__coerce__': <slot wrapper '__coerce__' of 'instance' objects>, '__contains__': <slot wrapper '__contains__' of 'instance' objects>, '__delattr__': <slot wrapper '__delattr__' of 'instance' objects>, '__delitem__': <slot wrapper '__delitem__' of 'instance' objects>, '__delslice__': <slot wrapper '__delslice__' of 'instance' objects>, '__div__': <slot wrapper '__div__' of 'instance' objects>, '__divmod__': <slot wrapper '__divmod__' of 'instance' objects>, ... ``` What are these, and what are they used for? Edit: This is the output from: ``` class A: pass b = A() print(type(b).__dict__) ```

Original source

Related problems