Skip to main content

Dethklok

We are here to make coffee metal. We will make everything metal. Blacker than the blackest black times infinity.

  • Nathan Explosion, Dethklok

The most uncompromising Python code formatter ever!

Dethklok uses a few code formatters under the hood:

  • astunparse -- extracted and improved unparse.py from the CPython source code. This script gets AST and formats it into the code, without knowing anything about how the code looked like before. From Python 3.9, it is a part of the standard library: ast.unparse.
  • autopep8 -- a powerful and mature code formatter. We run it to make the produced code a bit less ugly.

Installation

Supported Python versions are limited by what astunparse supports. For now, it's Python <=3.7.

python3 -m pip install --user dethklok

Usage

python3 -m dethklok format **/*.py

FAQ

Q: Is it flake8 compatible?

Almost. The tool outputs some statements in a single-line. The most noticeable example is docstrings. None of autoformatters I tried can make it multiline again.

Q: When should I use it?

The short answer is "NEVER". This is an experimental project that shows that producing the same AST without taking into account the initial formatting can't make the code readable. I am a mediaocre developer but still formatting of my code has an intention and makes the code more readable: I group elements, I left comments, I align columns, I parenthesize parts of complex arithmetic operations. While some parts of the code can be easily autoformatted without breaking it, some parts shouldn't.

Q: Is it a joke about black or what?

Well, a bit. Black targets to reformat everything, to have an opinion about part of every Python code. I admire that goal and really hope the project will grow and become mature some day. However, right now it's unstable and tries to fix things it can't fix (yet).

There are some formatters with similar philosophy in other languages (go format, cargo format, elixir format), and there are amazing. The difference is that these languages were designed with the formatter in mind, and every new feature is thoughtfully integrated with the formatter to make the result nice and idiomatic. Python is different.

Q: What should I use instead.

Luckily, there are plenty of cool formatters. They are doing only a small task but handle it really well. A few notable examples:

  • autopep8 fixes only parts of the code that flake8 complaints about.
  • isort groups and sorts imports.
  • add-trailing-comma adds trailing commas and formats long function call statements.
  • unify changes single quotes by double or vice versa, depends on what you prefer.

See the full list in awesome-python-code-formatters.

Release files for dethklok 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dethklok 1.0.0
File Size Uploaded
dethklok-1.0.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dethklok 1.0.0
File Interpreter ABI Platform
dethklok-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / dethklok-1.0.0.tar.gz

Download URL dethklok-1.0.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d261656839a44535c5deac911df95c972a59f63340d27b0e978696857479ae9f
BLAKE2b-256 checksum
How to use checksums
3dd04ff7ced7a05094c50abbbed38dfd093dae88bf7f39d01ef4056c9f9aa73e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via DepHell/0.8.3

Release files / dethklok-1.0.0-py3-none-any.whl

Download URL dethklok-1.0.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a09306030e32aa175d95199984cfcff36a4ce6130f49404965dc819a27e738a
BLAKE2b-256 checksum
How to use checksums
3fb778dd447d5b9116b0549789a972151c2451e9194d78efc63b3d192ebadaa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via DepHell/0.8.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page