Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow redundant parens in comprehension values. #43

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

robsdedude
Copy link
Owner

@robsdedude robsdedude commented Mar 22, 2024

Add an exception for redundant parentheses in comprehension value expressions (and key expressions for dict comprehensions) if they are multi-line.

Examples:

[
    (
        item.isoformat()
        if isinstance(item, datetime.datetime)
        else item
    )
    for item in data
]
{
    (
        k
        * SOME_LONG_KEY_MULTIPLIER_NAME_GOES_HERE
        + LONG_NAMES_CAN_BE_ANNOYINGLY_LONG_CANT_THEY
    ): (
        v[0]
        if isinstance(v, list) and len(v) == 1
        else v
    )
    for k, v in otherdict.items()
}

Not however:

(
    (i * 2)
    for i in range(100)
)

Closes: #42

Add an exception for redundant parentheses in comprehension value expressions
(and key expressions for dict comprehensions) if they are multi-line.

Examples:
```
[
    (
        item.isoformat()
        if isinstance(item, datetime.datetime)
        else item
    )
    for item in data
]
```

```
{
    (
        k
        * SOME_LONG_KEY_MULTIPLIER_NAME_GOES_HERE
        + LONG_NAMES_CAN_BE_ANNOYINGLY_LONG_CANT_THEY
    ): (
        v[0]
        if isinstance(v, list) and len(v) == 1
        else v
    )
    for k, v in otherdict.items()
}
```

*Not* however:
```
(
    (i * 2)
    for i in range(100)
)
```
@robsdedude robsdedude merged commit b0fb0cb into main Mar 22, 2024
7 checks passed
@robsdedude robsdedude deleted the add-multi-line-comprehension-value-exception branch March 22, 2024 14:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the exceptions don't seem to recognise comprehensions and complains about parens added by black
1 participant