What is a 'slot wrapper' in python?

前端 未结 3 651
一生所求
一生所求 2021-02-05 06:46

object.__dict__ and other places have their hidden methods set to things like this:

 

        
3条回答
  •  时光说笑
    2021-02-05 07:24

    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.

提交回复
热议问题