[Python-Dev] Backward incompatible change about docstring AST

Serhiy Storchaka storchaka at gmail.com
Tue Feb 27 17:48:25 EST 2018


28.02.18 00:31, Terry Reedy пише:
>> 2. Usually the position of the docstring is used for determining the 
>> absolute position of some fragments in the docstring (for example 
>> doctests). But since the literal string can contain \n and escaped 
>> newlines, and this information is lost in AST, the position of the 
>> fragment can be determined accurately.
> 
> You obviously meant 'cannot be determined accurately', because for 
> reasons including the ones you gave, the relation between string 
> literals in code and the resulting string objects is many-to-one, (as 
> with int literals).

Yes, thank you for correction.

The reasons are that the relation between lines of source code and lines 
of the resulting string objects is not easy. The string literal 'a\nb\c' 
takes one line in the source code, but produces a three-line string 
object. On other side, the string literal

     '''\
     abc\
     '''

takes three lines in the source code, but produces a single-line string 
object. And it is not so rare that a docstring starts with an escaped 
newline.



More information about the Python-Dev mailing list