E127: "continuation line over-indented" when comprehension is an argument
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 754
- PR merge metrics
- No merged PRs in 30d
Description
Consider
[obj for obj in iterator
if some_long_cond()
and some_other_cond()]
(obj for obj in iterator
if some_long_cond()
and some_other_cond())
sorted(obj for obj in iterator
if some_long_cond()
and some_other_cond())
I would consider that this is a reasonable, and perhaps even the correct way to indent such expressions, assuming you adhere to the "binary operators after linebreak" school and also assuming that the expressions are too long to fit in a single line.
Interestingly, pycodestyle is happy with the indenting of the first two expressions, but complains about the last one
test.py:9:11: E127 continuation line over-indented for visual indent
(Note that it is able to recognize the correct amount of indenting needed in the first two expressions -- adding or removing a space before "and" results in the same warning as for the third expression.)
Edit: note to self or whoever will work on this: the first two cases actually work "accidentally" because the indent of the last line is 4 characters, which is always accepted -- prepending the thing e.g. with the_list = [... and indenting the rest to align makes the thing fail again.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported examples with pycodestyle and trace the continuation-indent check that emits E127. Compare comprehension arguments with the first two examples and preserve existing E127 behavior; done when the reported valid indentation no longer produces a warning and the relevant existing checks still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100