This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Adding funcitonality to determine if a constant string node is triple quoted
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, methane, pablogsal, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-12-24 15:24 by BTaskaya, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg358850 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-24 15:24
I was working on a preceding system for AST unparser and @pablogsal said there is an issue with docstrings (they printed in the same line even it was like 1000 chars long). So determining something is a triple quoted or not is simple with preceding system but I think it would be better if we can do it simpler and public. 

What I am thinking is using col_offset and end_col_offset information to determine if a string is a triple quoted or not. With a function called `ast.is_triple_quoted` or `ast.get_quote_count` etc. 

I can submit a patch if this wanted.I dont think this is big enough to discuss it on python-ideas but if it is, then I'm happy to port discussion over there.
msg358877 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2019-12-26 06:09
I'm not sure the usage should be covered by "Abstract" syntax tree.

Isn't it a "Concrete" syntax tree?
msg358878 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-12-26 07:03
It is impossible because of using newline escaping and string literal concatenation. In the following examples 
lineno != end_lineno, but strings use single quotes:

    print('Hello '
          'world!')

    print('Hello\
 world!')

Triple quotes can be also used for strings which occupy a single line of code and do not contain \n:

    print("""exec("print('Hi!')")""")

We cannot also distinguish 1234 from 0x4_d2 and 1234.0 from 1.234e3 at the AST level.
msg358888 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-26 15:51
@inada.naoki I thought that would be a nice to have feature in certain cases AST used but as @serhiy.storchaka said there is an issue with implicit string concatenation which makes this impossible to expose. Thank you both.
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83313
2019-12-26 15:51:52BTaskayasetstatus: open -> closed

messages: + msg358888
stage: resolved
2019-12-26 07:03:29serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg358878
2019-12-26 06:09:39methanesetnosy: + methane
messages: + msg358877
2019-12-24 15:24:49BTaskayacreate