{"id":6636,"library":"flake8-literal","title":"Flake8 Literal","description":"flake8-literal is a Flake8 plugin designed to enforce consistent styling of string literals in Python code. It validates inline literals, multiline literals, and docstrings for quote usage (single or double quotes). Additionally, it includes checks for raw string usage, preventing unnecessary raw strings and enforcing their use when needed to avoid escaped backslashes. The current version is 1.5.0, and it is actively maintained.","status":"active","version":"1.5.0","language":"en","source_language":"en","source_url":"https://github.com/plinss/flake8-literal","tags":["flake8","linter","code-quality","style-guide","strings","python"],"install":[{"cmd":"pip install flake8-literal","lang":"bash","label":"Install"}],"dependencies":[{"reason":"This is a plugin for Flake8 and requires Flake8 to function.","package":"flake8"}],"imports":[],"quickstart":{"code":"# Create a file named 'example.py'\n# Then run flake8 example.py from your terminal\n\ndef check_quotes():\n    # L100: Use double quotes for inline literals (if configured)\n    inline_string = 'hello world'\n\n    # L101: Use single quotes for multiline literals (if configured)\n    multiline_string = \"\"\"\n    This is a multiline string.\n    \"\"\"\n\n    # L102: Use double quotes for docstrings (if configured)\n    \"\"\"This is a docstring with incorrect quotes (if configured).\"\"\"\n\n    # L103: Unnecessary raw string (if configured to avoid escapes)\n    path_string = r\"C:\\users\\name\"\n\n    import re\n    # L104: Regex pattern should be a raw string (if configured strictly)\n    regex_pattern = re.compile('[a-z]')\n\n# To configure flake8-literal, create a setup.cfg or .flake8 file:\n# For example, in setup.cfg:\n# [flake8]\n# literal-inline-quotes = double\n# literal-multiline-quotes = single\n# literal-docstring-quotes = double\n# literal-avoid-escape = true\n# literal-raw-regex-always-raw = true","lang":"python","description":"Install flake8-literal and then run `flake8` on your Python code. The plugin's checks will automatically be included. Configuration options can be specified in a `flake8` configuration file (e.g., `setup.cfg`, `pyproject.toml`, or `.flake8`) under the `[flake8]` section, or via command-line arguments."},"warnings":[{"fix":"Configure `flake8-literal` options (e.g., `literal-inline-quotes`) in your `setup.cfg` or `.flake8` file under the `[flake8]` section, or pass them as `--literal-inline-quotes=double` arguments to the `flake8` command.","message":"flake8-literal is a plugin and does not expose symbols for direct import into Python code. Its functionality is integrated by running the `flake8` command-line tool. All configurations are done through `flake8`'s configuration files (e.g., `setup.cfg`, `.flake8`) or command-line options, not within Python code.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `re` functions are called directly with raw string literals for `flake8-literal` to apply its raw string regex checks, or be aware that indirect assignments will bypass this specific check.","message":"The raw string validation feature for regular expression patterns (e.g., `L104`) has a specific limitation: it only works when string literals are directly passed as arguments to `re` module functions (e.g., `re.compile(r'...')`) and these functions are called directly (not aliased or stored in variables first). Indirect usages, like defining a pattern string in a variable and then passing it to `re.compile(pattern)`, will not be checked.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always install `flake8` and its plugins within the same Python environment. If encountering unexpected behavior, check the `flake8` and `flake8-literal` documentation for any specific version compatibility notes. Use `pip install --upgrade flake8 flake8-literal` to ensure you have recent, compatible versions.","message":"As a `flake8` plugin, `flake8-literal`'s effectiveness can depend on the version of `flake8` being used. While `flake8-literal` requires Python >=3.12, ensure that your installed `flake8` version is compatible with this plugin and with your Python environment. Major updates to `flake8` can sometimes introduce changes in how plugins are discovered or configured.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}