1
class A(object):
    class B(object): pass
    class C(A.B): pass

results in

NameError: name 'A' is not defined

How do I inherit from B in C, if they are adjacent , both nested in A (inner classes)?

1 Answer 1

4

You cannot use A until the class body has finished executing.

You can refer to 'local' names; the class body is executed as a function, and the local namespace of that function is used to supply the class attributes; within the class body, B is a local name:

class A(object):
    class B(object): pass
    class C(B): pass
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.