[New-bugs-announce] [issue16806] col_offset is -1 for multiline string expressions resembling docstrings

Carsten Klein report at bugs.python.org
Sat Dec 29 01:08:22 CET 2012

New submission from Carsten Klein:

Given an input module such as

class klass(object):
    """multi line comment
    continued on this line

    """single line comment"""

    Another multi

and implementing a custom ast.NodeVisitor such as

import as

class CustomVisitor(ast.NodeVisitor):

    def visit_ClassDef(self, node):

        for childNode in node.body:


    def visit_Expr(self, node):


and feeding it the compiled ast from the module above

f = open('./module.py')
source = f.read()
node = ast.parse(source, mode = 'exec')
visitor = CustomVisitor()

should yield -1/-1 for the docstring that is the first
child node expression of the classdef body.

it will, however, yield the correct col_offset of 4/4 for
the single line docstring following the first one.

the multi line docstring following that will again
yield a -1/-1 col_offset.

It believe that this behaviour is not correct and instead
the col_offset should be 4 for both the expression node
and its str value.

components: Interpreter Core
messages: 178444
nosy: carsten.klein at axn-software.de
priority: normal
severity: normal
status: open
title: col_offset is -1 for multiline string expressions resembling docstrings
type: enhancement
versions: Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list