[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2022-03-16 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> Incorrect exception highlighting for fstring format

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2022-03-16 Thread Daniël van Noord

Daniël van Noord  added the comment:

This was fixed by https://github.com/python/cpython/pull/27729.

On 3.10:
```console
>>> ast.parse("f'{a}'").body[0].value.values[0].value.col_offset
3
>>> ast.parse("f'{a:b}'").body[0].value.values[0].value.col_offset
3
```

The other issue also no longer reproduces.

--
message_count: 3.0 -> 4.0
nosy: +danielnoord
nosy_count: 5.0 -> 6.0
pull_requests: +30022
pull_request: https://github.com/python/cpython/pull/27729

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2021-01-18 Thread daniel hahler


Change by daniel hahler :


--
nosy: +blueyed

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2020-08-31 Thread Aaron Meurer


Aaron Meurer  added the comment:

The same thing occurs with specifiers like {a!r}.

--
nosy: +asmeurer

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2020-04-06 Thread yang


Change by yang :


--
keywords: +patch
nosy: +fhsxfhsx
nosy_count: 2.0 -> 3.0
pull_requests: +18760
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19398

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2019-10-04 Thread Arminius


Arminius  added the comment:

There is another instance of incorrectly reported offsets in f-strings, in this 
case affecting multi-line strings.

Example:

(
f'aaa{foo}bbb'
f'ccc{bar}ddd'
f'eee{baz}fff'
)

Relevant part of the syntax tree:

JoinedStr(
lineno=2,
col_offset=4,
values=[
Str(lineno=2, col_offset=4, s='aaa'),
FormattedValue(
lineno=2,
col_offset=4,
value=Name(lineno=2, col_offset=10, id='foo', ctx=Load()),
conversion=-1,
format_spec=None,
),
Str(lineno=2, col_offset=4, s='bbbccc'),
FormattedValue(
lineno=2,
col_offset=4,
value=Name(lineno=2, col_offset=5, id='bar', ctx=Load()),
conversion=-1,
format_spec=None,
),
Str(lineno=2, col_offset=4, s='dddcccaa'),
FormattedValue(
lineno=2,
col_offset=4,
value=Name(lineno=2, col_offset=5, id='baz', ctx=Load()),
conversion=-1,
format_spec=None,
),
Str(lineno=2, col_offset=4, s='ddd'),
],
),

The reported code position for "foo" is correct (2,10), but not for "bar" (2,5) 
and "baz" (2,5).


Could you give an estimate as to whether this issue will be looked at any time 
soon?

--

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2018-11-11 Thread Eric V. Smith


Change by Eric V. Smith :


--
assignee:  -> eric.smith

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2018-11-11 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +eric.smith

___
Python tracker 

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



[issue35212] Expressions with format specifiers in f-strings give wrong code position in AST

2018-11-11 Thread Arminius


New submission from Arminius :

ast.parse() will give a wrong code position for an expression inside an 
f-string when the expression is using a format specifier.

Compare the trees of f'{a}' and f'{a:b}' :

>>> ast.parse("f'{a}'")
Module(
body=[
Expr(
lineno=1,
col_offset=0,
value=JoinedStr(
lineno=1,
col_offset=0,
values=[
FormattedValue(
lineno=1,
col_offset=0,
value=Name(lineno=1, col_offset=3, id='a', ctx=Load()),
conversion=-1,
format_spec=None,
),
],
),
),
],
)

>>> ast.parse("f'{a:b}'")
Module(
body=[
Expr(
lineno=1,
col_offset=0,
value=JoinedStr(col_offset=0,
lineno=1,
col_offset=0,
values=[
FormattedValue(
lineno=1,
col_offset=0,
value=Name(lineno=1, col_offset=1, id='a', ctx=Load()),
conversion=-1,
format_spec=JoinedStr(
lineno=1,
col_offset=0,
values=[Str(lineno=1, col_offset=0, s='b')],
),
),
],
),
),
],
)

In both examples, the name "a" is at the same position in the source code, 
however the parsed ASTs yield two different offsets,

Name(lineno=1, col_offset=3, id='a', ctx=Load())

and

Name(lineno=1, col_offset=1, id='a', ctx=Load())

.

Expected behavior: col_offset=3 for name "a" in both f-strings.

(In my specific use case, this breaks a semantic highlighting plugin for vim.)

--
components: Interpreter Core
messages: 329672
nosy: arminius
priority: normal
severity: normal
status: open
title: Expressions with format specifiers in f-strings give wrong code position 
in AST
type: behavior
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