-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make example paths shorter & get markdown example better
- Loading branch information
1 parent
f02e63f
commit c3700cf
Showing
5 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
--- | ||
title: 🟡 pydantic | ||
hide: | ||
- toc | ||
--- | ||
|
||
!!! warning "Partially compatible" | ||
Pydantic models will raise an error if to try to inherit them from `Exception`, but we can use Pydantic `dataclasses` instead. Idea: [:simple-github: pydantic/pydantic#1875](https://github.com/pydantic/pydantic/issues/1875) | ||
!!! info inline end "Idea" | ||
[:simple-github: pydantic/pydantic#1875](https://github.com/pydantic/pydantic/issues/1875) | ||
|
||
* :slight_frown: Pydantic models will raise an error if to try to inherit them from `Exception` and then `raise`, | ||
* :slight_smile: but we can use Pydantic `dataclasses` instead. | ||
|
||
{{ run_python_script("examples/pydantic_exception.py") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,22 @@ | ||
--- | ||
title: 🟡 rich | ||
hide: | ||
- toc | ||
--- | ||
|
||
## 🟢 `Documented` | ||
|
||
```python | ||
import rich | ||
from documented import Documented | ||
|
||
|
||
class MyMessage(Documented): | ||
""" | ||
This is a Markdown formatted message. | ||
* _One_, | ||
* *Two*, | ||
* `Three` | ||
and **more** features of Markdown | ||
> are supported. | ||
""" | ||
|
||
rich.print(MyMessage()) | ||
``` | ||
{{ run_python_script("examples/rich-markdown.py") }} | ||
|
||
This will render the docstring as Markdown in the console. | ||
|
||
## 🟡 `DocumentedError` | ||
|
||
It's easy to write an exception with console markup or Markdown formatted text, catch that exception and `rich.print()` it for user's information. | ||
!!! info inline end "See related thread" | ||
[:simple-github: textualize/rich#2619](https://github.com/Textualize/rich/issues/2619) | ||
|
||
I haven't found a way to integrate [:simple-github: rich](https://github.com/textualize/rich/) with `documented` directly, to render beautiful exceptions with console markup or Markdown text in them right in the traceback. | ||
* :slight_frown: I haven't found a way to integrate [:simple-github: rich](https://github.com/textualize/rich/) with `documented` directly, to render beautiful exceptions with console markup or Markdown text in them right in the traceback. | ||
|
||
Related thread: [:simple-github: textualize/rich#2619](https://github.com/Textualize/rich/issues/2619). | ||
* :slight_smile: However, this can always be done manually: | ||
* `except` the error, | ||
* and `rich.print()` it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import rich | ||
from documented import Documented | ||
|
||
|
||
class MyMessage(Documented): | ||
""" | ||
# This is a Markdown formatted message. | ||
* _One_, | ||
* *Two*, | ||
* `Three` | ||
and **more** features of Markdown | ||
> are supported. | ||
""" | ||
|
||
|
||
rich.print(MyMessage()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters