[Python-bugs-list] [ python-Bugs-503837 ] type.__module__ problems (again?)

noreply@sourceforge.net noreply@sourceforge.net
Fri, 08 Mar 2002 20:58:31 -0800


Bugs item #503837, was opened at 2002-01-15 13:10
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=503837&group_id=5470

Category: Type/class unification
Group: Python 2.2
Status: Open
Resolution: Fixed
Priority: 5
Submitted By: Roeland Rengelink (rengelink)
Assigned to: Guido van Rossum (gvanrossum)
Summary: type.__module__ problems (again?)

Initial Comment:
Gelukkig nieuwjaar,

This is probably related to previous bug reports on
type.__module__.

Given

--- A.py ---
class meta1(type):
    def __new__(tp, name, bases, attr):
        return type.__new__(tp, name, bases, attr)

class meta2(type):
    pass

--- B.py ---
import A
class B1(object):
    __metaclass__ = A.meta1

class B2(object):
    __metaclass__ = A.meta2

------------

I get the following session.

Python 2.2 (#4, Jan  7 2002, 11:59:25) 
[GCC 2.95.2 19991024 (release)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import B
>>> B.B1.__module__
'A'
>>> B.B2.__module__
'B'

Among others, this problem causes pydoc to only display
documentation for B2 as part of the docs for module B.

Presumably, the behaviour for B2 is correct.

Regards,

Roeland Rengelink


----------------------------------------------------------------------

>Comment By: Roeland Rengelink (rengelink)
Date: 2002-03-09 04:58

Message:
Logged In: YES 
user_id=302601

This bug is now also reported under #516532

----------------------------------------------------------------------

Comment By: Roeland Rengelink (rengelink)
Date: 2002-01-16 08:16

Message:
Logged In: YES 
user_id=302601

I came upon the other bug reports by browsing the bug
database, but I didn't write the numbers down. The only ones
I did find again when I looked this morning are:

#442501
#487390

Neither are really related to the problem reported here
though,

Thanks for the fix.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-01-15 21:07

Message:
Logged In: YES 
user_id=6380

Fixed in compile.c 2.235, by initializing __module__ to the
contents of the global variable __name__ at the start of the
class statement. Not 100% satisfied with that, but can't
come up with something better right now.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-01-15 17:33

Message:
Logged In: YES 
user_id=6380

You're right. This is because __module__ is taken from the
globals of the currently executing Python code.

This is clearly a bug. I'll have to think about how to fix
it -- maybe the class statement will have to set it.

I can't find the other bug reports related to __module__;
the SF search box apparently searches for "module" when I
type that in the search box, and that hits about every other
bug report ever submitted, including closed ones. :-(

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=503837&group_id=5470