[Python-Dev] Trouble with Python 2.3a1

David Abrahams dave@boost-consulting.com
Wed, 08 Jan 2003 13:04:46 -0500


Guido van Rossum <guido@python.org> writes:

>> Ralf describes below a change in the name of classes defined in the
>> __main__ module for 2.3a1, which causes some of our tests to fail.
>> Was it intentional?
>
> I need more information.  __main__ gets prepended in certain
> situations when no module name is given.  I don't recall exactly what
> changed.

OK, here's some more information.  I'd just give you a test case, but
making a 'C' testcase that isn't tied to Boost.Python will take a lot
of work in this instance.

My extension module, 'simple' is creating a class derived from
'object' by calling my own metaclass, which is derived from PyTypeType
and basically adds nothing to it.

The new class is called 'empty'.  In order to ensure that empty gets
the right __module__ attribute, I followed your suggestion of
prepending the module name and a dot to the class name before passing
it on to the metaclass I'm invoking.

The output below shows that in 2.3a1, that module prefix string is
discarded in favor of the name of the module which imports the
extension module.

Python 2.2.1 (#2, Jun 17 2002, 12:06:51) 
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import simple
module_prefix result: simple.
>>> simple.empty.__module__
'simple'
>>> 

Python 2.3a1 (#1, Jan  6 2003, 14:17:56) 
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import simple
module_prefix result: simple.
>>> simple.empty.__module__
'__main__'
>>> 


-- 
                       David Abrahams
   dave@boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution