flake8-picky-parentheses
flake8-picky-parentheses is a flake8 plugin that enhances code style checks by nitpicking about the usage and alignment of parentheses, brackets, and braces. It provides two main types of checks: identifying redundant parentheses (PAR0xx codes) and enforcing opinionated alignment rules for multi-line expressions (PAR1xx codes). The library is actively maintained, frequently updating to ensure compatibility with the latest Python versions and flake8 releases, with its current version being 0.6.2.
Common errors
-
flake8: error: unrecognized arguments: --select=PAR0,PAR1
cause This error typically indicates that `flake8-picky-parentheses` is not installed or detected by `flake8`, or that you are using an older version of `flake8` that does not support plugin selection via `--select` for uninstalled plugins.fixEnsure `flake8-picky-parentheses` is installed in your environment (`pip install flake8-picky-parentheses flake8`). If using `--require-plugins`, ensure `flake8` is at least version 5.0.0. If the plugin is installed but still not found, `flake8 --version` should list `picky-parentheses` under 'Plugins'. -
PAR101: Opening bracket is last, but closing is not on new line
cause The plugin's opinionated alignment checker (PAR1xx group) has detected a style violation where an opening bracket (or parenthesis/brace) on one line does not have its corresponding closing bracket on a new, correctly indented line.fixAdjust your code to match the plugin's alignment expectations (e.g., place the closing bracket on a new line with matching indentation). Alternatively, if this rule conflicts with your preferred style or an auto-formatter, disable the specific error code `PAR101` or the entire `PAR1` group using `flake8 --extend-ignore='PAR1'` or in your configuration file.
Warnings
- gotcha The alignment checks (PAR1xx codes) provided by `flake8-picky-parentheses` are opinionated and may not align with all coding styles or formatters (e.g., Black).
- gotcha When using `flake8 --require-plugins flake8-picky-parentheses`, ensure that your `flake8` installation is version 5.0.0 or higher. Older versions do not support this option.
- gotcha `flake8` plugins, including `flake8-picky-parentheses`, are tied to the Python version on which `flake8` itself is installed. To correctly parse modern Python syntax, ensure `flake8` is installed within a compatible Python environment.
Install
-
pip install flake8-picky-parentheses flake8 -
flake8 --require-plugins flake8-picky-parentheses <path/to/your/code>
Quickstart
import os
def my_function():
if (True): # PAR001: Redundant parentheses (general)
result = ((1 + 2) * 3) # PAR001: Redundant parentheses (general)
else:
result = (
4 + 5 # PAR101: Opening bracket is last, but closing is not on new line
) * 6
(a,) = 'b' # PAR002: Parentheses used for tuple unpacking
return a