A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-February/132614.html below:

[Python-Dev] Tangent on class level scoping rules (was Re: PEP 463: Exception-catching expressions)

[Python-Dev] Tangent on class level scoping rules (was Re: PEP 463: Exception-catching expressions) [Python-Dev] Tangent on class level scoping rules (was Re: PEP 463: Exception-catching expressions)Eric Snow ericsnowcurrently at gmail.com
Fri Feb 21 22:55:54 CET 2014
On Fri, Feb 21, 2014 at 7:42 AM, Nick Coghlan <ncoghlan at gmail.com> 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.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4