A linter to manage your exception like a PRO!
Project description
Manage your exceptions in Python like a PRO
Currently in BETA. Inspired by this blog post.
I shared the building process of this tool here.
“For those who like dinosaurs 🦖 and clean try/except ✨ blocks.”
Installation and usage
Installation
pip install tryceratops
Usage
tryceratops [filename or dir...]
You can enable experimental analyzers by running:
tryceratops --experimental [filename or dir...]
You can ignore specific violations by using: --ignore TCXXX repeatedly:
tryceratops --ignore TC201 --ignore TC202 [filename or dir...]
You can exclude dirs by using: --exclude dir/path repeatedly:
tryceratops --exclude tests --exclude .venv [filename or dir...]
flake8 Plugin
🦖 Tryceratops is also a plugin for flake8, so you can:
❯ flake8 --select TC src/tests/samples/violations/call_raise_vanilla.py
src/tests/samples/violations/call_raise_vanilla.py:13:9: TC002 Create your own exception
src/tests/samples/violations/call_raise_vanilla.py:13:9: TC003 Avoid specifying long messages outside the exception class
src/tests/samples/violations/call_raise_vanilla.py:21:9: TC201 Simply use 'raise' without specifying exception object again
Violations
All violations and its descriptions can be found in docs.
Ignoring violations
If you want to ignore a violation in a specific file, you can either:
- Add a comment with
notcto the top of the file you want to ignore - Add a comment with
notcto the line you want to ignore - Add a comment with
notc: CODEto the line you want to ignore a specific violation
Example:
def verbose_reraise_1():
try:
a = 1
except Exception as ex:
raise ex # notc: TC202
Configuration
You can set up a pyproject.toml file to set rules.
This is useful to avoid reusing the same CLI flags over and over again and helps to define the structure of your project.
Example:
[tool.tryceratops]
exclude = ["samples"]
ignore = ["TC002", "TC200", "TC300"]
experimental = true
CLI flags always overwrite the config file.
Pre-commit
If you wish to use pre-commit, add this:
- repo: https://github.com/guilatrova/tryceratops
rev: v0.2.5
hooks:
- id: tryceratops
License
MIT
Credits
Thanks to God for the inspiration 🙌 ☁️ ☀️
Logo icon was made by https://www.freepik.com
The black project for insights.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tryceratops-0.2.5.tar.gz.
File metadata
- Download URL: tryceratops-0.2.5.tar.gz
- Upload date:
- Size: 445.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96a0c49d6ccf612520c5b9cdd0137f4f8a3bb7a4464e83f6f9aaaff1612a2b3a
|
|
| MD5 |
37f9f2eaa158bd7cd2a65c5cf7afe5c6
|
|
| BLAKE2b-256 |
651e27af6eac7ec36f9f7dd72a420fcd7f3a13a5305665443e7f8dfd1740386e
|
File details
Details for the file tryceratops-0.2.5-py3-none-any.whl.
File metadata
- Download URL: tryceratops-0.2.5-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dc5461b80243e6b6d071b083ded75e903645581b0988d1b65d4be8ddde3ff3f
|
|
| MD5 |
645c5a2cd3a030c292acac5637b556f3
|
|
| BLAKE2b-256 |
f1ee5bc7891f591704e8a08988d60526501697e5beec384d0d4f9358c9de33e9
|