Skip to content

Conversation

@jacobtylerwalls
Copy link
Member

Type of Changes

Type
🔨 Refactoring

Description

The f-string brain rewrites line numbers for FormattedValue.value (a Name node) because of a brief period where the line numbers were incorrect.

The line number issue was solved in CPython shortly after the brain was contributed, see python/cpython#74650.

Demo

>>> from astroid import extract_node
>>> node = extract_node("""
... x = 'x'
... y = f'{x}'
... """)
>>> node.value
<JoinedStr l.3 at 0x104843fe0>
>>> node.value.values
[<FormattedValue l.3 at 0x1048600b0>]
>>> node.value.values[0].value
<Name.x l.3 at 0x104860110>

The line number issue was solved in CPython shortly after
the brain was contributed.
@jacobtylerwalls jacobtylerwalls added topic-performance pylint-tested PRs that don't cause major regressions with pylint Maintenance Discussion or action around maintaining astroid or the dev workflow labels Jul 28, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.3.0 milestone Jul 28, 2024
@jacobtylerwalls jacobtylerwalls merged commit 76d5429 into main Jul 28, 2024
@jacobtylerwalls jacobtylerwalls deleted the jtw/remove-fstring-brain branch July 28, 2024 16:40
@Pierre-Sassoulas
Copy link
Member

Nice !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintenance Discussion or action around maintaining astroid or the dev workflow pylint-tested PRs that don't cause major regressions with pylint topic-performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants