<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
<br>
The problem: if you're currently in a nested class, you can't look
up variables in the outer "class scope".<br>
<br>
For example, this code fails in Python 3:<br>
<blockquote><tt>class Outer:<br>
class Inner:<br>
class Worker:<br>
pass<br>
<br>
class InnerSubclass(Inner):<br>
class Worker(Inner.Worker):<br>
pass</tt><br>
</blockquote>
It fails at the definition of Worker inside InnerSubclass. Python 3
can't find "Inner", in order to get to "Inner.Worker".<br>
<br>
Adding "global Inner" just above that line doesn't help--it's not a
global.<br>
Adding "nonlocal Inner" just above that line doesn't help either--I
suppose it's the <i>wrong kind</i> of nonlocal. nonlocal is for
nested functions, and this uses nested classes.<br>
<br>
You can tell me YAGNI, but I tripped over this because I wanted it.
It's not a contrived example. I actually use inner classes a lot; I
suppose I'm relatively alone in doing so.<br>
<br>
Yes, I could make the problem go away if I didn't have nested inner
classes like this. But I like this structure. Any idea how I can
make it work while preserving the nesting and inheritance?<br>
<br>
Thanks,<br>
<br>
<br>
<i>larry</i><br>
<i></i>
</body>
</html>