[issue30497] Line number of docstring in AST

2017-05-29 Thread Steven Myint

Steven Myint added the comment:

I think what you guys have brought up makes sense.

Now that you mention it, I see that pyflakes gives the wrong line number if an 
escaped newline appears after the doctests. Though, it works fine if the 
escaped newline appears before it.

https://github.com/PyCQA/pyflakes/blob/1af4f14ad4675bf5c61c47bbb7c2421b50d1cba4/pyflakes/checker.py#L842

This is a non-default feature in pyflakes anyway, so we can live with it.

Thanks

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30497] Line number of docstring in AST

2017-05-29 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Even if the line number of a docstring is known, it is not easy to determine 
the line number corresponding to the particular line in a docstring if it 
contains backslashes following by newline.

'''foo
bar
'''

and

'''\
foo
bar
'''

are equal strings, but the lines 'bar' have different offsets from the start of 
the strings.

The only robust method was parsing the source code starting from the start of a 
docstring. Now you just need to start parsing from the start of the 
function/class.

--
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30497] Line number of docstring in AST

2017-05-29 Thread STINNER Victor

STINNER Victor added the comment:

> We use this feature in pyflakes (https://github.com/PyCQA/pyflakes/issues/271)

AST is not designed to be 1-to-1 .py source to AST mapping. If you need the 
exact line number, you might use your own parser. I don't know what is using 
pylint for example? There is also https://github.com/PyCQA/redbaron which 
provides such 1-to-1 mapping but it has a different API than AST.

Sadly, I suggest to close this issue as WONTFIX.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30497] Line number of docstring in AST

2017-05-29 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It is not possible anymore. Why you need the line number of a docstring?

The closest approximation is between node.lineno and node.body[0].lineno (if 
node.body is not empty).

--
nosy: +haypo, inada.naoki, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30497] Line number of docstring in AST

2017-05-28 Thread Steven Myint

New submission from Steven Myint:

Since #29463, it is no longer obvious how to get the line number of a docstring 
in the AST:

import ast

x = ast.parse('''\
def foo():
"""This is a docstring."""
''')

# In Python 3.6, the docstring and line number would be:
print(x.body[0].body[0].value.s)
print(x.body[0].body[0].value.lineno)

# In Python 3.7, I don't know what the equivalent would be.
print(x.body[0].docstring)
# Line number?

We use this feature in pyflakes (https://github.com/PyCQA/pyflakes/issues/271).

--
components: Interpreter Core
messages: 294654
nosy: myint
priority: normal
severity: normal
status: open
title: Line number of docstring in AST
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com