How does inheritance of __slots__ in subclasses actually work?

前端 未结 5 1635
南笙
南笙 2020-12-02 08:29

In the Python data model reference section on slots there is a list of notes on using __slots__. I am thoroughly confused by the 1st and 6th items, because the

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 09:23

    My understanding is as follows:

    • class X has no __dict__ <-------> class X and its superclasses all have __slots__ specified

    • in this case, the actual slots of the class are comprised from the union of __slots__ declarations for X and its superclasses; the behavior is undefined (and will become an error) if this union is not disjoint

提交回复
热议问题