Message188979
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. |
|
Date |
User |
Action |
Args |
2013-05-12 06:25:55 | ncoghlan | set | recipients:
+ ncoghlan, gvanrossum, barry, benjamin.peterson, ezio.melotti, alex, eli.bendersky, docs@python, ethan.furman, python-dev, zach.ware |
2013-05-12 06:25:55 | ncoghlan | set | messageid: <1368339955.73.0.263511969426.issue17947@psf.upfronthosting.co.za> |
2013-05-12 06:25:55 | ncoghlan | link | issue17947 messages |
2013-05-12 06:25:55 | ncoghlan | create | |
|