On Fri, Feb 21, 2014 at 7:42 AM, Nick Coghlan <[email protected]> wrote:
> It's a relatively arcane scoping rule that only matters if you have
> non-trivial logic at class scope. The vast majority of Python
> programmers will never have to care, because they do the typical thing
> and their class bodies consist almost entirely of function definitions
> and relatively simple assignment statements.
That is definitely an esoteric corner. It's only really bitten me
when I was doing stuff with nested classes [1] and mined too deeply.
Here's a simple example:
class Spam:
class Ham:
A = None
B = None
class Eggs:
class Bacon(Ham):
A = 3
If I recall correctly, Larry Hastings ran into something similar a while back.
-eric
[1] The nested classes were used just for easy-to-read namespaces,
effectively hijacking the class definition syntax with no intention of
actually using the class as a type.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com