Skip to main content

Make sure arguments in Python function definitions are indented by 8 spaces

Project description

py-def-indent-formatter

A command line tool (and a pre-commit hook) to automatically format haning indentation in Python function definitions to 8 spaces.

Currently, this tool is only designed to work properly after your Python files have been formatted by black or blue.

Motivation of this tool

black and blue both use only 4 spaces as haning indentation in function definitions, which is not aligned with PEP8's recommendation.

Therefore, this tool specifically fixes this 4-space style choice of black and blue.

Installation

pip install format-def-indent

Usage

As a command line tool

format-def-indent <PATH_THAT_CONTAINS_PYTHON_FILES>

Use --help to see documentations of command line arguments.

As a pre-commit hook

Put the following into your .pre-commit-config.yaml file:

-   repo: https://github.com/cyyc1/py-def-indent-formatter
    rev: v0.1.3
    hooks:
    -   id: format-def-indent

See pre-commit for more instructions.

What does this formatter do

This tool formats the following "before" (red) into "after" (green).

Multi-line arguments in function definitions:

def some_function(
-    arg1,
-    arg2='test',
-    *,
-    arg3: int = 2,
-    arg4: bool = False,
+        arg1,
+        arg2='test',
+        *,
+        arg3: int = 2,
+        arg4: bool = False,
) -> None:
    print(1)

or

def some_functions(
-    arg1,
-    *args,
-    **kwargs,
+        arg1,
+        *args,
+        **kwargs,
):
    print(1)

Single-line arguments in function definitions:

def some_function(
-    arg1, arg2='test', *, arg3: int = 2, arg4: bool = False,
+        arg1, arg2='test', *, arg3: int = 2, arg4: bool = False,
):
    print(1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

format_def_indent-0.1.4.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

format_def_indent-0.1.4-py2.py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page