This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients andyharrington, arigo, benjamin.peterson, rhettinger, stutzbach
Date 2011-02-27.21:44:13
SpamBayes Score 0.0005902466
Marked as misclassified No
Message-id <1298843055.51.0.144063338717.issue11339@psf.upfronthosting.co.za>
In-reply-to
Content
This would be an important fix-up if we could find some way to implement it.

The basic problem is that the class object is defined after the class definitions have been made, so the target of the Graph reference isn't known when the method definitions are being compiled.

One approach to solving this problem is to use a deferred/resolved pattern (creating a valid reference to Graph that is visible during method compilation, but gets filled-in with the other methods afterwards).

I haven't thought this through completely but think it could be done if we let the compiler write to the class dictionary (this is normally off-limits and protected by a dict_proxy).  If we let the system punch a hole in the proxy, it is possible to resolve deferred class definitions.


class Prepared(type):
    'Preload the class with a reference to itself'

    @classmethod
    def __prepare__(mcl, name, bases):
        return {name: type(name, bases, {})}

    def __new__(mcl, name, bases, mapping):
        tmpcls = super().__new__(mcl, name, bases, mapping)
        deferred_class = mapping[name]
        deferred_class.__dict__.update(tmpcls.__dict__)  # XXX need writeable dict_proxy
        return deferred_class

class Graph(metaclass=Prepared):
    def reverse(self) -> Graph:
        ...
History
Date User Action Args
2011-02-27 21:44:15rhettingersetrecipients: + rhettinger, arigo, andyharrington, benjamin.peterson, stutzbach
2011-02-27 21:44:15rhettingersetmessageid: <1298843055.51.0.144063338717.issue11339@psf.upfronthosting.co.za>
2011-02-27 21:44:13rhettingerlinkissue11339 messages
2011-02-27 21:44:13rhettingercreate