Skip to content

Black collapses lists in return type annotations onto one line, regardless of the "magic" trailing comma. #3018

@alexreinking

Description

@alexreinking

Describe the bug

Black collapses lists in return type annotations onto one line, regardless of the "magic" trailing comma.

To Reproduce

For example, take this code:

@hl.generator(name="simplepyfn")
def SimplePyFn(
    context: hl.GeneratorContext,
    buffer_input: Buffer[UInt8, 2],
    func_input: Buffer[Int32, 2],
    float_arg: Scalar[Float32],
    offset: int = 0,
) -> tuple[
    Buffer[UInt8, 2],
    Buffer[UInt8, 2],
]:
    """
    ... more code here ...
    """

And run it with these arguments:

$ black file.py --target-version py39

The resulting file contains:

@hl.generator(name="simplepyfn")
def SimplePyFn(
    context: hl.GeneratorContext,
    buffer_input: Buffer[UInt8, 2],
    func_input: Buffer[Int32, 2],
    float_arg: Scalar[Float32],
    offset: int = 0,
) -> tuple[Buffer[UInt8, 2], Buffer[UInt8, 2],]:
    """
    ... more code here ...
    """

Expected behavior

I would have expected the code to either

  1. Not be reformatted due to the magic trailing comma (preferred)
  2. Have the trailing comma removed. (worse)

Environment

  • Black's version: black, 22.3.0 (compiled: yes)
  • OS and Python version: Ubuntu 20.04.3 LTS (WSL), Python 3.8.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions