pythonvisual-studio-codeformattingautoformattingautoformat

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

  • 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
    )