psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.78k stars 2.44k forks source link

Removal of redundant parenthesis causes surprising formatting #2581

Open intgr opened 2 years ago

intgr commented 2 years ago

Using Black 21.9b0

Describe the style change

This code is successfully formatted and accepted by Black:

assert name.rfc4514_string(
    {NameOID.COMMON_NAME: "CommonName", NameOID.EMAIL_ADDRESS: "E"}
) == ("CommonName=Santa Claus,E=santa@northpole.fi")
#    ^                                             ^

The parenthesis on the last line are redundant and can be removed. I wouldn't expect the formatting to be changed by Black.

However, with this input:

assert name.rfc4514_string(
    {NameOID.COMMON_NAME: "CommonName", NameOID.EMAIL_ADDRESS: "E"}
) == "CommonName=Santa Claus,E=santa@northpole.fi"

The result is

assert (
    name.rfc4514_string(
        {NameOID.COMMON_NAME: "CommonName", NameOID.EMAIL_ADDRESS: "E"}
    )
    == "CommonName=Santa Claus,E=santa@northpole.fi"
)
felix-hilden commented 2 years ago

I'll label this as a bug, since clearly the parens could just be removed. Thanks for reporting!