Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 340cbe7

Browse files
committed
A tentative fix for SF bug #503837 (Roeland Rengelink):
type.__module__ problems (again?) This simply initializes the __module__ local in a class statement from the __name__ global. I'm not 100% sure that this is the correct fix, although it usually does the right thing. The problem is that if the class statement executes in a custom namespace, the __name__ global may be taken from __builtins__, in which case it would have the value __builtin__, or it may not exist at all (if the custom namespace also has a custom __builtins__), in which case the class statement will fail. Nevertheless, unless someone finds a better solution, this is a 2.2.1 bugfix too.
1 parent 7668957 commit 340cbe7

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

Python/compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,6 +3926,9 @@ compile_classdef(struct compiling *c, node *n)
39263926
/* classdef: 'class' NAME ['(' testlist ')'] ':' suite */
39273927
c->c_name = STR(CHILD(n, 1));
39283928
c->c_private = c->c_name;
3929+
/* Initialize local __module__ from global __name__ */
3930+
com_addop_name(c, LOAD_GLOBAL, "__name__");
3931+
com_addop_name(c, STORE_NAME, "__module__");
39293932
ch = CHILD(n, NCH(n)-1); /* The suite */
39303933
doc = get_docstring(c, ch);
39313934
if (doc != NULL) {

0 commit comments

Comments
 (0)