psf / black

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

Redundant parentheses around return annotation #2041

Closed NeilGirdhar closed 2 years ago

NeilGirdhar commented 3 years ago
def infer_encoding_trajectory(encoding: EncodingElement,
                              observation: PoolingMessage,
                              prediction: PredictionMessage,
                              weights: hk.Params,
                              rng: Generator,
                              iterations: int) -> (
                                  tuple[EncodingState, EncodingTrajectory]):

became

def infer_encoding_trajectory(
    encoding: EncodingElement,
    observation: PoolingMessage,
    prediction: PredictionMessage,
    weights: hk.Params,
    rng: Generator,
    iterations: int,
) -> (tuple[EncodingState, EncodingTrajectory]):

The parentheses were only there to allow wrapping and should have been removed. In general, black doesn't need to preserve parentheses around an entire expression, including a type annotation.

JelleZijlstra commented 3 years ago

I agree, a PR would be welcome. In general, there's a number of places where Black should remove parentheses that it currently keeps. From past experience it's tricky sometimes to remove parentheses without causing stability bugs, but maybe in this context it won't be too bad.