cwacek / python-jsonschema-objects

Automatic Python binding generation from JSON Schemas
MIT License
363 stars 96 forks source link

cleanup: Improve style, formatting; use flake8, isort #254

Closed EliahKagan closed 1 year ago

EliahKagan commented 1 year ago

This is a style cleanup, to increase code clarity and consistency, supported by manual inspection, flake8, and isort. Most, but not all, of these changes are to formatting, or to the way imports are sorted and grouped (including removing unused imports and placing groups in the PEP-8 recommended order). I've tried to include only Python code changes that I think can be considered improvements whether or not flake8 and isort continue to be used (though I recommend them). This fully retains black style, as well as the central role of black as the main tool for enforcing and checking style in the project.

This adds flake8, which had a configuration in setup.cfg (and had previously been used with Hound), as well as isort. It configures them for consistency with black and with the overall preexisting style. This includes changing the line length to 88, which black uses. The old pep8 configuration is removed, because pep8 was renamed to pycodestyle, and the old pycodestyle is removed, because it doesn't need to be run directly, since flake8 runs it and passes it an appropriate configuration derived from its own. This sets up flake8 and isort for local use, but it does not add them to CI.

Although flake8 detects many things black does not, they partially overlap in their detection of overly long lines. The black rule is more nuanced, rightly skipping over long strings in test data that would be less clear if split across multiple lines. However, flake8 detects comments and docstrings that should be wrapped, so I didn't turn off that flake8 rule. (Such long strings in tests are the only cases where an inline noqa: suppression was needed.)

Besides tool-recommended changes, these other changes are included:

Notable omissions: