Inheritance and inner classes in Python?

后端 未结 3 1347

In the following code class B has inherited yay attribute from class A, I expected this. I\'d also expect that inner class B.Foo

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

    Inheritance is a per-class thing. In your code class B inherits from class A, but just because both of them have inner class Foo doesn't tell us anything about their inheritance.

    If you want B.Foo to have the attributes from A.Foo, you need to make B.Foo inherit from A.Foo:

    class B(A):
        class Foo(A.Foo):
            bob = False
    

提交回复
热议问题