]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
A couple of fixes for the compiler package:
authorMichael W. Hudson <mwh@python.net>
Mon, 7 Oct 2002 12:21:09 +0000 (12:21 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 7 Oct 2002 12:21:09 +0000 (12:21 +0000)
 * always write the mtime to a .pyc in little endian format
 * ensure class's docstrings get attached to the class, not the
   enclosing scope!

Rather more fixes are needed for the trunk; these will be done in due
course.

Lib/compiler/pycodegen.py
Lib/compiler/symbols.py

index 4194d27e25e7167d2b680ad8a2dc94e68500acda..88146cde69ff23f945857b51b9f9578d4cca6a54 100644 (file)
@@ -136,7 +136,7 @@ class Module(AbstractCompileMode):
         # to indicate the type of the value.  simplest way to get the
         # same effect is to call marshal and then skip the code.
         mtime = os.stat(self.filename)[stat.ST_MTIME]
-        mtime = struct.pack('i', mtime)
+        mtime = struct.pack('<i', mtime)
         return self.MAGIC + mtime
 
 class LocalNameFinder:
@@ -389,9 +389,6 @@ class CodeGenerator:
     def visitClass(self, node):
         gen = self.ClassGen(node, self.scopes,
                             self.get_module())
-        if node.doc:
-            self.emit('LOAD_CONST', node.doc)
-            self.storeName('__doc__')
         walk(node.code, gen)
         gen.finish()
         self.set_lineno(node)
@@ -1306,6 +1303,10 @@ class ClassCodeGenerator(NestedScopeMixin, AbstractClassCode, CodeGenerator):
         self.__super_init(klass, scopes, module)
         self.graph.setFreeVars(self.scope.get_free_vars())
         self.graph.setCellVars(self.scope.get_cell_vars())
+        self.set_lineno(klass)
+        if klass.doc:
+            self.emit("LOAD_CONST", klass.doc)
+            self.storeName("__doc__")
 
 def generateArgList(arglist):
     """Generate an arg list marking TupleArgs"""
index cd7bcebe0f83cbaf84ff906701fdcbdf7e0e01f4..dd5cd26e7fd64f75affd957259f83f6516a5c9cd 100644 (file)
@@ -249,6 +249,8 @@ class SymbolVisitor:
         scope = ClassScope(node.name, self.module)
         if parent.nested or isinstance(parent, FunctionScope):
             scope.nested = 1
+        if node.doc is not None:
+            scope.add_def('__doc__')
         self.scopes[node] = scope
         prev = self.klass
         self.klass = node.name