Skip to content

Commit

Permalink
add tutorial 005 to showcase pretty_exceptions_width
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Apr 18, 2024
1 parent f4b44a4 commit 0d209d8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/tutorial/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ $ python main.py

</div>


## Set Output Width

If you want to control the width of the yellow and red Rich exception borders, you can set the parameter `pretty_exceptions_width` to an integer:

```Python hl_lines="3"
{!../docs_src/exceptions/tutorial005.py!}
```

This prevents artificial line breaks in cases where there is sufficient horizontal space on the console.

## Disable Pretty Exceptions

You can also entirely disable pretty exceptions with the parameter `pretty_exceptions_enable=False`:
Expand Down
37 changes: 37 additions & 0 deletions docs_src/exceptions/tutorial005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import typer

app = typer.Typer(pretty_exceptions_width=120)


@app.command()
def main(name: str = "morty"):
deep_dict_or_json = {
"this_is_a_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"this_is_the_next_long_key": {
"and_once_again_a_very_long_key": {
"but_this_is_not_the_end": {"end": True}
}
}
}
}
}
}
}
}
}
}
}
}
print(name + 3)


if __name__ == "__main__":
app()

0 comments on commit 0d209d8

Please sign in to comment.