Skip to main content

Pretty error messages

Project description

Pretty Err

PyPI version

A simple library for printing modern, source-annotated error messages.

Features

  • source span annotation
  • color output
  • multiple non-overlapping spans
  • zero-width spans

Install

pip install prettyerr

Example

Say you have the following source code that contains an error

def repeat(message: str, times: int) -> str:
    return message * times

result = repeat("hello", "3")
print(result)

A nice error message might look something like this

Error: type mismatch for argument `times`

    ╭─[path/to/py_example.py:4:10]
  4 | result = repeat("hello", "3")
    ·          ──┬───          ─┬─
    ·            │              ╰─ argument given is type 'str'
    ·            ╰─ `repeat` function's second argument `times` expects an 'int'
    ╰───
  help: Consider changing string literal "3" to integer 3

To render this error message:

from prettyerr import Error, PointerMessage, Span, SrcFile

src = """\
def repeat(message: str, times: int) -> str:
    return message * times

result = repeat("hello", "3")
print(result)
"""

e = Error(
    SrcFile(py_src, "path/to/py_example.py"),
    title="type mismatch for argument `times`",
    pointer_messages=[
        PointerMessage(span=Span(82, 88), message="`repeat` function's second argument `times` expects an 'int'"),
        PointerMessage(span=Span(98, 101), message="argument given is type 'str'"),
    ],
    hint='Consider changing string literal "3" to integer 3',
)
print(e)

Tasks

  • set up slaving to dewy-lang repo error.py
  • set up workflow to periodically check for changes to error.py (maybe once per week?)
    • on change, create a PR using the newest version of the error.py
    • run tests to make sure everything is still working
    • if tests fail, note that in the PR (e.g. if I move error.py, the script would fail to pull it in, etc.)
    • PR should assign me so that I know to deal with it
    • TBD if a previous PR hasn't been merged what to do, perhaps just let it make a new PR?
  • improve README

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prettyerr-0.0.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prettyerr-0.0.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file prettyerr-0.0.1.tar.gz.

File metadata

  • Download URL: prettyerr-0.0.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prettyerr-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3ec19aa3503113a1713d1ccf28534eaa59d76fcba1cd4bd37f414e27f14a47d3
MD5 7bd2b1d7fe5636c6591a58c3a0f343c7
BLAKE2b-256 acaf32562607d942ef77305f0b980c72370fe202336383956b3d35b45b9be014

See more details on using hashes here.

File details

Details for the file prettyerr-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: prettyerr-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prettyerr-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 caeef66f647dd2e0581d06e90f4c36c7e219f254efa3f390fe7ae10a267030e9
MD5 dd8674cf92ff530b1f754ee69a485f96
BLAKE2b-256 786ed2a3662babb9870bf0bc2cf00cbc5c336fd5d214aa3676abcc16455618da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page