Skip to main content

Flake8 plugin to encourage correct string literal concatenation

Project description

flake8-implicit-str-concat

PyPI version Supported Python versions PyPI downloads GitHub Actions status Codecov Licence Code style: Black Tidelift

This is a plugin for the Python code-checking tool Flake8 to encourage correct string literal concatenation.

It looks for style problems like implicitly concatenated string literals on the same line (which can be introduced by the code-formatting tool Black), or unnecessary plus operators for explicit string literal concatenation.

Install

pip install flake8-implicit-str-concat

Example

$ cat example.py
s = ('111111111111111111111'
     '222222222222222222222')
$ black example.py
reformatted example.py
All done! ✨ 🍰 ✨
1 file reformatted.
$ cat example.py
s = "111111111111111111111" "222222222222222222222"
$ flake8 example.py
example.py:1:28: ISC001 implicitly concatenated string literals on one line
$ edit example.py # Remove the " " and save
$ cat example.py
s = "111111111111111111111222222222222222222222"
$ black example.py
All done! ✨ 🍰 ✨
1 file left unchanged.
$ flake8 example.py
$

Violation codes

The plugin uses the prefix ISC, short for Implicit String Concatenation.

Code Description
ISC001 implicitly concatenated string literals on one line
ISC002 implicitly concatenated string literals over continuation line
ISC003 explicitly concatenated string should be implicitly concatenated
ISC004 unparenthesized implicit string concatenation in collection

ISC004

Checks for implicitly concatenated strings inside list, tuple, and set literals.

In collection literals, implicit string concatenation is often the result of a missing comma between elements, which can silently merge items together.

# Bad
facts = (
    "Lobsters have blue blood.",
    "The liver is the only human organ that can fully regenerate itself.",
    "Clarinets are made almost entirely out of wood from the mpingo tree."
    "In 1971, astronaut Alan Shepard played golf on the moon.",
)

# Good
facts = (
    "Lobsters have blue blood.",
    "The liver is the only human organ that can fully regenerate itself.",
    "Clarinets are made almost entirely out of wood from the mpingo tree.",
    "In 1971, astronaut Alan Shepard played golf on the moon.",
)

If the concatenation is intentional, wrap it in parentheses to make it explicit:

# Good
facts = (
    "Lobsters have blue blood.",
    "The liver is the only human organ that can fully regenerate itself.",
    (
        "Clarinets are made almost entirely out of wood from the mpingo tree."
        "In 1971, astronaut Alan Shepard played golf on the moon."
    ),
)

Release notes

You can find the release notes on the releases page.

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_implicit_str_concat-0.7.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

flake8_implicit_str_concat-0.7.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file flake8_implicit_str_concat-0.7.0.tar.gz.

File metadata

File hashes

Hashes for flake8_implicit_str_concat-0.7.0.tar.gz
Algorithm Hash digest
SHA256 492d6d1097ec51ca9e712bef9c5b2e8345867dfa8c744a12bf4ef014fdb18561
MD5 47abb7b4676ed97b9ecd7be1984145ee
BLAKE2b-256 b083cb6050d37bd7bcf01dc81ac20d3db96ffc41aca7f73f81fbf61223d5aa03

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_implicit_str_concat-0.7.0.tar.gz:

Publisher: release.yml on flake8-implicit-str-concat/flake8-implicit-str-concat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flake8_implicit_str_concat-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_implicit_str_concat-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fdabd6c6a314678364053b4a8682495692a43c22f229358e801f711999340d8b
MD5 4be1a0ba74098ceb66a9d9e27f4c2614
BLAKE2b-256 f83af4906c442afbfea281d7e03322c1761670dca950a4ef4abf1cab218fbc96

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_implicit_str_concat-0.7.0-py3-none-any.whl:

Publisher: release.yml on flake8-implicit-str-concat/flake8-implicit-str-concat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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