'How to auto format python kwargs to newlines in VS Code?

In VS Code, Python: How can keyword arguments:

    number = models.CharField(
        max_length=10, unique=True, verbose_name=_('Contract number'))

be automatically formatted into separate lines:

    number = models.CharField(
        max_length=10,
        unique=True,
        verbose_name=_('Contract number')
    )

I wasn't able to find such configuration option, is there a way to archive/force the above formatting style?



Solution 1:[1]

Use black as your formatter and then add a comma , after the last argument in your function definition and black will span them to new lines:

number = models.CharField(
    max_length=10,
    unique=True,
    verbose_name=_('Contract number'),  # note the comma here
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Wolf