Skip to main content

A flake8 plugin to make sure complex conditional expressions and comprehension expressions are split over several lines.

Project description

flake8-multiline-conditionals-comprehensions

Build Status Build Status Build Status Build Status

flake8 plugin that works on conditional expressions and comprehension expressions to enforce each segment to be put on a new line.

Contents

Options

The flag --select_c20 can be used to select the set of errors to include. By default, the active errors are C2000, C2001, C2002, C2020, C2021, C2023.

Comprehension Errors

C2000

A comprehension expression should place each of its generators on a separate line.

# Bad
[x+y for x in range(10) for y in range(10)]

# Good
[
    x + y
    for x in range(10)
    for y in range(10)
]

C2001

A multiline comprehension expression should place each of its segments (map, generator, filter) on a separate line.

# Bad
[x+y for x in range(10) 
for y in range(10) if x+y > 5]

# Good
[
    x + y
    for x in range(10)
    for y in range(10)
    if x + y > 5
]

C2002

A comprehension expression should not contain multiple filters.

# Bad
[x for x in range(10) if x % 2 == 0 if x % 3 == 0]

# Good
[x for x in range(10) if x % 2 == x % 3 == 0]

C2003

A comprehension expression should not span over multiple lines.

# Bad
[x + y 
for x in range(10) ]

# Good
[x+y for x in range(10)]

C2004

A comprehension expression should span over multiple lines.

# Bad
[x for x in range(10)]

# Good
[x 
for x in range(10)]

Condition Errors

C2020

A multiline conditional expression should place each of its segments on a separate line.

# Bad
1 
if something() else 0

# Good
1
if something()
else 0

C2021

A conditional expression used for assignment should be surrounded by parantheses.

# Bad
a = 1 if something() else 0

# Good
a = (1 if something() else 0)

C2022

A conditional expression should not contain further conditional expressions.

# Bad
1 if x > 0 else -1 if x < 0 else 0

# Good
if x > 0:
    return 1
elif x < 0:
    return -1
else:
    return 0

C2023

A conditional expression should not span over multiple lines.

# Bad
1
if something()
else 0

# Good
1 if something() else 0

C2024

A conditional expression should span over multiple lines.

# Bad
1 if something() else 0

# Good
1
if something()
else 0

C2025

Conditional expressions should not be used.

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

Built Distribution

File details

Details for the file flake8-multiline-conditionals-comprehensions-1.1.tar.gz.

File metadata

  • Download URL: flake8-multiline-conditionals-comprehensions-1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for flake8-multiline-conditionals-comprehensions-1.1.tar.gz
Algorithm Hash digest
SHA256 ab599e08d1ca2684dfbf11b5c22d9ab47bf221483aee86cfa6ea398ae84bea79
MD5 c3f69328617e1f1e6b190f95b01b7b6e
BLAKE2b-256 b2acc224abdb8d5b1e71e7fea5c9cf956b4e6ce83fe8a5a325a10ee618955f7a

See more details on using hashes here.

File details

Details for the file flake8_multiline_conditionals_comprehensions-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_multiline_conditionals_comprehensions-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4551914ec1da09a79c960edff7e08a9c789eed70a2441aa515c55feb93c2874d
MD5 d6e21f362c42b896cce2b9c5ed5f1cb3
BLAKE2b-256 1278128d5809249d112fa436583b3c04a94d929a325ca12042dcd0764dfd3245

See more details on using hashes here.

Supported by

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