Re: [Python-Dev] [Python-checkins] peps: Add Alexandre's suggestions
On Tue, Aug 16, 2011 at 11:30 AM, antoine.pitrou
+Serializing "pseudo-global" objects +----------------------------------- + +Objects which are not module-global, but should be treated in a similar +fashion -- such as methods [4]_ or nested classes -- cannot currently be +pickled (or, rather, unpickled) because the pickle protocol does not +correctly specify how to retrieve them. One solution would be through the +adjunction of a ``__namespace__`` (or ``__qualname__``) to all class and +function objects, specifying the full "path" by which they can be retrieved. +For globals, this would generally be ``"{}.{}".format(obj.__module__, obj.__name__)``. +Then a new opcode can resolve that path and push the object on the stack, +similarly to the GLOBAL opcode. +
I think this is the part that ties in with the pickle-related aspects for PEP 395 - using '__qualname__' would be one way to align a module's real name with where it should be retrieved from and where it's documentation lives (I like 'qualified name' as a term, too). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Tue, 16 Aug 2011 12:35:48 +1000
Nick Coghlan
On Tue, Aug 16, 2011 at 11:30 AM, antoine.pitrou
wrote: +Serializing "pseudo-global" objects +----------------------------------- + +Objects which are not module-global, but should be treated in a similar +fashion -- such as methods [4]_ or nested classes -- cannot currently be +pickled (or, rather, unpickled) because the pickle protocol does not +correctly specify how to retrieve them. One solution would be through the +adjunction of a ``__namespace__`` (or ``__qualname__``) to all class and +function objects, specifying the full "path" by which they can be retrieved. +For globals, this would generally be ``"{}.{}".format(obj.__module__, obj.__name__)``. +Then a new opcode can resolve that path and push the object on the stack, +similarly to the GLOBAL opcode. +
I think this is the part that ties in with the pickle-related aspects for PEP 395 - using '__qualname__' would be one way to align a module's real name with where it should be retrieved from and where it's documentation lives (I like 'qualified name' as a term, too).
Oops, I admit I hadn't read PEP 395. PEP 395 focuses on module aliasing, while the suggestion above focuses on the path of objects in modules. How can we reconcile the two? Do we want __qualname__ to be a relative "path" inside the module? (but then __qualname__ cannot specify its own module name). Regards Antoine.
On Tue, Aug 16, 2011 at 7:25 PM, Antoine Pitrou
On Tue, 16 Aug 2011 12:35:48 +1000 Nick Coghlan
wrote: On Tue, Aug 16, 2011 at 11:30 AM, antoine.pitrou
wrote: +Serializing "pseudo-global" objects +----------------------------------- + +Objects which are not module-global, but should be treated in a similar +fashion -- such as methods [4]_ or nested classes -- cannot currently be +pickled (or, rather, unpickled) because the pickle protocol does not +correctly specify how to retrieve them. One solution would be through the +adjunction of a ``__namespace__`` (or ``__qualname__``) to all class and +function objects, specifying the full "path" by which they can be retrieved. +For globals, this would generally be ``"{}.{}".format(obj.__module__, obj.__name__)``. +Then a new opcode can resolve that path and push the object on the stack, +similarly to the GLOBAL opcode. +
I think this is the part that ties in with the pickle-related aspects for PEP 395 - using '__qualname__' would be one way to align a module's real name with where it should be retrieved from and where it's documentation lives (I like 'qualified name' as a term, too).
Oops, I admit I hadn't read PEP 395. PEP 395 focuses on module aliasing, while the suggestion above focuses on the path of objects in modules. How can we reconcile the two? Do we want __qualname__ to be a relative "path" inside the module? (but then __qualname__ cannot specify its own module name).
I was more thinking that if pickle grew the ability to handle two different names for objects, then PEP 395 could run off the same feature without having to mess with sys.modules. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Tue, 16 Aug 2011 20:15:51 +1000
Nick Coghlan
Oops, I admit I hadn't read PEP 395. PEP 395 focuses on module aliasing, while the suggestion above focuses on the path of objects in modules. How can we reconcile the two? Do we want __qualname__ to be a relative "path" inside the module? (but then __qualname__ cannot specify its own module name).
I was more thinking that if pickle grew the ability to handle two different names for objects, then PEP 395 could run off the same feature without having to mess with sys.modules.
But what happens if a module contains, say, a nested class with a __qualname__ (assigned by the interpreter) of "module_name.A.B", and the module later gets a __qualname__ (assigned by the user) of "module_alias"? Regards Antoine.
On Tue, Aug 16, 2011 at 9:23 PM, Antoine Pitrou
On Tue, 16 Aug 2011 20:15:51 +1000 Nick Coghlan
wrote: Oops, I admit I hadn't read PEP 395. PEP 395 focuses on module aliasing, while the suggestion above focuses on the path of objects in modules. How can we reconcile the two? Do we want __qualname__ to be a relative "path" inside the module? (but then __qualname__ cannot specify its own module name).
I was more thinking that if pickle grew the ability to handle two different names for objects, then PEP 395 could run off the same feature without having to mess with sys.modules.
But what happens if a module contains, say, a nested class with a __qualname__ (assigned by the interpreter) of "module_name.A.B", and the module later gets a __qualname__ (assigned by the user) of "module_alias"?
Yeah, I don't think it works with PEP 395 in its current state. But then, I'm not sure 395 will work at all in its current state - definitely a work in progress, that one. However, I'll definitely keep this aspect in mind next time I update it - even if they don't use the same mechanism, they should at least be compatible proposals. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (2)
-
Antoine Pitrou
-
Nick Coghlan