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 ncoghlan
Recipients alex, barry, benjamin.peterson, docs@python, eli.bendersky, ethan.furman, ezio.melotti, gvanrossum, ncoghlan, python-dev, zach.ware
Date 2013-05-12.06:25:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368339955.73.0.263511969426.issue17947@psf.upfronthosting.co.za>
In-reply-to
Content
Guido has promised an explanation for why he wants to keep the frame hack once he is back at work next week. To help him target that reply appropriately for my concrete objections to retaining it, I'd like to explain a bit more about why I think it's fundamentally impossible to create a robust stack inspection mechanism for implicit pickling support. Even if a dedicated mechanism for it is added, the information the interpreter needs to make a sensible reliable decision simply isn't there.

Consider the following:

    # In utils.py
    def enum_helper(name, prefix, fields):
        if isinstance(fields, str): fields = fields.split()
        e = Enum(name, (prefix + field for field in fields))
        return e

    # In some other module
    from utils import enum_helper
    MyEnum = enum_helper(MyEnum, "st_", "mtime atime ctime")

This breaks the frame hack, but would work correctly if enum_helper was redesigned to accept an explicit module name, or if we adopted something like the "name binding protocol" discussed on Python ideas.

If we adopted a simplistic rule of ignoring function scopes and only look at module and class scopes, then we break the semantics of the global keyword.

I consider the frame hack fundamentally broken, since there's currently no way the interpreter can distinguish between an incidental assignment (like the "e = Enum..." call in util.py) and a destination assignment (like the "MyEnum = enum_helper..." call), and if we *do* add a different syntax for "this supports pickling" assignments (like the def name = expr syntax on Python ideas), then a name binding protocol makes more sense than implicit contextual magic.
History
Date User Action Args
2013-05-12 06:25:55ncoghlansetrecipients: + ncoghlan, gvanrossum, barry, benjamin.peterson, ezio.melotti, alex, eli.bendersky, docs@python, ethan.furman, python-dev, zach.ware
2013-05-12 06:25:55ncoghlansetmessageid: <1368339955.73.0.263511969426.issue17947@psf.upfronthosting.co.za>
2013-05-12 06:25:55ncoghlanlinkissue17947 messages
2013-05-12 06:25:55ncoghlancreate