What is the correct (or best) way to subclass the Python set class, adding a new instance variable?

前端 未结 7 913
囚心锁ツ
囚心锁ツ 2021-01-01 20:45

I\'m implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to

相关标签:
7条回答
  • 2021-01-01 21:00

    It looks like set bypasses __init__ in the c code. However you will end an instance of Fooset, it just won't have had a chance to copy the field.

    Apart from overriding the methods that return new sets I'm not sure you can do too much in this case. Set is clearly built for a certain amount of speed, so does a lot of work in c.

    0 讨论(0)
提交回复
热议问题