A linter to manage all your python exceptions and try/except blocks (limited only for those who like dinosaurs).
  • Python 99.9%
  • Shell 0.1%
Find a file
github-actions eb6f551696 0.2.6
Automatically generated by python-semantic-release
2021-07-21 01:03:17 +00:00
.github/workflows ci: set up python 3.8 for release 2021-07-20 22:00:32 -03:00
bin chore: set up linters 2021-06-19 09:00:26 -03:00
docs 0.2.6 2021-07-21 01:03:17 +00:00
img docs: rename image to clear cache 2021-06-30 11:44:30 -03:00
src 0.2.6 2021-07-21 01:03:17 +00:00
.gitignore chore: ignore dist 2021-06-20 15:50:14 -03:00
.pre-commit-config.yaml chore: exclude samples in pre-commit 2021-07-20 21:27:58 -03:00
.pre-commit-hooks.yaml feat: add support to pre-commit-hooks 2021-06-21 18:38:06 -03:00
CHANGELOG.md 0.2.6 2021-07-21 01:03:17 +00:00
dev-requirements.txt style: lint and bump line len to 100 2021-06-23 08:41:12 -03:00
LICENSE chore: set up flit to distribute package 2021-06-20 15:19:27 -03:00
poetry.lock chore: add python-semantic-release 2021-07-20 21:27:58 -03:00
pyproject.toml 0.2.6 2021-07-21 01:03:17 +00:00
README.md 0.2.6 2021-07-21 01:03:17 +00:00
requirements.txt feat: add support for pyproject.toml 2021-06-30 11:17:02 -03:00
setup.cfg style: lint and bump line len to 100 2021-06-23 08:41:12 -03:00

Manage your exceptions in Python like a PRO

Actions Status PyPI Semantic Release GitHub Downloads Code style: black try/except style: tryceratops Open in Visual Studio Code

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...]

example

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 notc to the top of the file you want to ignore
  • Add a comment with notc to the line you want to ignore
  • Add a comment with notc: CODE to 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.6
    hooks:
      - id: tryceratops

Show your style

try/except style: tryceratops

Add this fancy badge to your project's README.md:

[![try/except style: tryceratops](https://img.shields.io/badge/try%2Fexcept%20style-tryceratops%20%F0%9F%A6%96%E2%9C%A8-black)](https://github.com/guilatrova/tryceratops)

Extra Resources

If you want to read more about:

Contributing

Thank you for considering making Tryceratops better for everyone!

Refer to Contributing docs.

License

MIT

Credits

Thanks to God for the inspiration 🙌 ☁️ ☀️

Logo icon was made by https://www.freepik.com

The black project for insights.