Perfect forwarding - in Python

后端 未结 2 896
猫巷女王i
猫巷女王i 2021-01-04 11:06

I am a maintainer of a Python project that makes heavy use of inheritance. There\'s an anti-pattern that has caused us a couple of issues and makes reading difficult, and I

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 11:53

    Consider using attrs module:

    import attr
    
    @attr.s
    class Base(object):
        a = attr.ib(1)
        b = attr.ib(2)
        c = attr.ib(3)
        d = attr.ib(4)
        e = attr.ib(5)
        f = attr.ib(6)
        g = attr.ib(7)
    
    @attr.s
    class DerivedA(Base):
        z = attr.ib(0)
    
    der_a = DerivedA()
    print(der_a.a, der_a.z)
    

提交回复
热议问题