2016-06-03 7:15 GMT+02:00 Steven D'Aprano steve@pearwood.info:
On Thu, Jun 02, 2016 at 02:55:25PM +0200, Piotr Duda wrote:
I want to extend it to: some object also need to know module they're declared and their own qualified name (for example for pickling support).
If you are serious about this, then you should start a thread about it.
You should give some examples of which objects need this, and how people currently solve the problem, and why it is unsuitable.
If I have understood you correctly, the usual solution to this is to use sys._getframe(1). I don't know what Jython and IronPython use.
Examples would be any type object created by function that need pickling support, like stdlib namedtuple or Enum, both of them use _getframe hack as default, but this doesn't work in Jython or IronPython, and doesn't work if they're wrapped by another function, Enum also allow explicity specify module and qualname via keyword arguments, like:
Animal = Enum('Animal', 'ant bee cat dog', module=__name__, qualname='SomeData.Animal')
with new syntax:
def Animal = Enum('ant bee cat dog')