Skip to main content

A package that checks to ensure spaces around `=` in multiline function calls

Project description

flake8-multiline-function-call-equals

A (higly opinonated) flake8 extension that checks for spaces around = in multiline function calls

Motivation

For improved readability, function calls that span multiple physical lines should have a single space on either side of the = when using named arguments. Additionally, each physical line may hve exatly one argument (named, or otherwise).

By contrast, there should be no spaces around the =, when a function with named arguments is called on one physical line (i.e. not a multiline function call)

Examples

EQA100

foo(a = 5, b = 2)

This is a single line function call with named arguments. In this case, there should be no spaces around the = when passing values to the named arguments. The correct call would be

foo(a=5, b=2)

EQA101

foo(a  = 5,  # incorrect
    b = 2,  # correct
    )

This is a multiline function call with named arguments. In this case, there should be a single space on each side of the = when passing values to the named arguments. The correct call would be

foo(a = 5,
    b = 2,
    )

EQA102

foo(a= 5,  # incorrect - no space on the left
    b = 2,  # correct
    )
foo(a=5,  # incorrect - no spaces at all
    b = 2,  # correct
    )

These are multiline function calls with named arguments. In these cases, there should be a single space on each side of the = when passing values to the named arguments. The correct call would be

foo(a = 5,
    b = 2,
    )

EQA103

foo(a = 5,
           # incorrect - there should be no empty line here
    b = 2,
    )
foo(a = 5,
    b = 2,
           # incorrect - there should be no empty line here
    )

These are multiline function calls with named arguments. In these cases, there should be no empty lines within the function call. The correct call would be

foo(a = 5,
    b = 2,
    )

EQA104

foo(a = 5, b = 2,  # incorrect - only one argument per line
    )
foo(3, 4,  # incorrect - only one argument per line
    a = 5,
    b = 2,
    )

These are multiline function calls. In these cases, only one argument may be listed per line. The correct calls would be

foo(a = 5,
    b = 2,  # incorrect - only one argument per line
    )
foo(3,
    4,  # incorrect - only one argument per line
    a = 5,
    b = 2,
    )

EQA105

foo(  # incorrect - the first argument should be on this line
    a = 5,
    b = 2,
    )

This is a multiline function call. In this case, the first argument should be on the line with the open paren. The correct call would be

foo(a = 5,
    b = 2,
    )

EQA106

foo(a = 5,
    b = 2,)  # incorrect - closing paren should be on a separate line

This is a multiline function call. In this case, the closing parenthesis should be on its own line. The correct call would be

foo(a = 5,
    b = 2,
    )

List of Error Codes

Code Description
EQA100 Too many whitespaces surrounding assignment operator in single-line function call
EQA101 Too many whitespaces surrounding assignment operator in multiline function call
EQA102 Too few whitespaces surrounding assignment operator in multiline function call
EQA103 Empty line in multiline function call
EQA104 Multiple arguments on the same line in multiline function call
EQA105 First argument does not start on the call line in multiline function call
EQA106 Closing paren is on the same line as the last argument

Limitations

Python's AST parser does not mention the position of the = in argument passing. Consequently, the following code block will pass linting, even though it violates the spirit of the rule this linter attempts to enforce

foo(a=  5,  # this will incorrectly pass the lint check
    b = 2,
    )

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

flake8-multiline-function-call-equals-0.1.4.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file flake8-multiline-function-call-equals-0.1.4.tar.gz.

File metadata

File hashes

Hashes for flake8-multiline-function-call-equals-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f4b3d97fc703f0a15d3041bf318cb79b10d143431f20cce2598c13753e5b578f
MD5 5e6feeabe2a4554e3b506446ed3be46b
BLAKE2b-256 9483dc18eace296b492bce91f35f67ca590192da4202e94c1cdeef1139c0a509

See more details on using hashes here.

File details

Details for the file flake8_multiline_function_call_equals-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_multiline_function_call_equals-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 21551274f6d0469bf1053210128efb3e167ea1d3d01242037885d9cc3ad8fdec
MD5 dbc336032dadf1f01e3c5fee234cf36d
BLAKE2b-256 4054a46b4d379d49b9e5ff3bc564b90780e087c68c34ee160847c7c7045dab19

See more details on using hashes here.

Supported by

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