Author steven.daprano
Recipients abarry, levkivskyi, steven.daprano
Date 2016-12-04.23:15:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480893331.16.0.582578212969.issue28869@psf.upfronthosting.co.za>
In-reply-to
Content
I had a brief look at the source for ABCMeta, and it seems to me that the __module__ behaviour is coming from `type`. I'm not sure whether it can, or should, can be fixed in type, but I think that the correct behaviour for ABCMeta is to set __module__ to the caller's global "__name__", not its own.

Something like this should probably work:


class ABCMeta(type):
    def __new__(mcls, name, bases, namespace):
        if '__module__' not in namespace:
            # globals()['__name__'] gives 'abc'
            frame = inspect.currentframe()
            if frame is not None:
                # IronPython? 
                caller_globals = frame.f_back.f_globals
                namespace['__module__'] = caller_globals['__name__']
        cls = super().__new__(mcls, name, bases, namespace)
        ...
History
Date User Action Args
2016-12-04 23:15:31steven.dapranosetrecipients: + steven.daprano, levkivskyi, abarry
2016-12-04 23:15:31steven.dapranosetmessageid: <1480893331.16.0.582578212969.issue28869@psf.upfronthosting.co.za>
2016-12-04 23:15:31steven.dapranolinkissue28869 messages
2016-12-04 23:15:31steven.dapranocreate