PyCQA / PyCQA/pycodestyle

E122: No valid indent for long function call nested in f-string?

Open
#1,242 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

For the following example

class T:
    def m1(self):
        print(f"""
preamble
{some_long_func(
    some_long_arg, other_long_arg, more_long_arg)}
postamble
""")

    def m2(self):
        print(f"""
preamble
{some_long_func(
     some_long_arg, other_long_arg, more_long_arg)}
postamble
""")

there appears to be no indentation of the "long args line" that makes pycodestyle not emit a E122 ("continuation line missing indentation or outdented") for that line. (If m1 and m2 are toplevel functions and not methods, then the second form makes pycodestyle happy.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two class-method examples and tracing the E122 check that handles continuation lines inside nested f-strings. Done means the valid indentation case no longer emits E122 while the relevant existing checks continue to pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.