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.1rc0.tar.gz (20.6 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.1rc0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prettyerr-0.0.1rc0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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.1rc0.tar.gz
Algorithm Hash digest
SHA256 d9a25fd9fe45b30b06f4d6c220cdbd964a34dd32960f4823715958086e034ec4
MD5 104732be365642de45ee3a33ca304c2c
BLAKE2b-256 ca12ddcc1290c9348bd900749c184245d70b4fd4351211fa5067b581da80c789

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prettyerr-0.0.1rc0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f1dd919cadd7fff55566b70f514262e5df26640db0af76d749eab41469db6e0
MD5 52ff6a48902658c7d572ee2cc30249da
BLAKE2b-256 6472b974cd54fa220e2bf827cb31cd2ecac814ee2fbba17d92c1f90854c72dae

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