#269: Get Rich and replace your cat
Published Thu, Feb 3, 2022,
recorded Wed, Feb 2, 2022
Watch the live stream:
About the show
Sponsored by Datadog: pythonbytes.fm/datadog
Special guest: Luciana and Brett Cannon
Brian #1:rich-cli
- suggested by Lance Reinsmith
rich
on the command line.- why?
- syntax highlighting
rich example.py
rich -m README.md
use-m
for markdown- why Will?
.md
seems clear enough to me.
- why Will?
- comes with themes. ex:
--theme monokai
- formats json,
--json
or-j
- syntax highlighting
- and a bunch of other features I probably won’t use, but you might.
- alignment, maybe
- width, yeah, I’ll probably use
-w
- a bunch more
- In my .zshrc:
alias cat='rich --theme monokai'
- after
pipx install rich-cli
- feel free to tell me that I shouldn’t used cat for looking at file contents. (although, why not?)
- I’m not, I’m using rich. :)
- after
Luciana #2: debugpy - a debugger for Python
- The debugger we use in the Python extension for VS Code
- Super heplful features that can save up a lot of time and a lot of folks don’t seem to know about:
- Conditional breakpoints
- Helpful when you want the code to break only on a specific condition
- e.g. # of execution times, or when an expression is true
- Debug console
- Helpful for quick testing using the context of the program at the breakpoint
- Temp edits on variable values, expresison evaluation, etc.
- Jump to Cursor (a.k.a. Set Next Statement)
- Control on what is the next line the debugger will execute
- Including previously executed lines
- Conditional breakpoints
Brian #3: Documentation unit tests
- Simon Willison
- Post talking about using pytest and tests to check documentation.
- Simon has test code that
- introspects the code
- introspects the docs
- then makes sure some items are definitely in the docs
- This is used in Datasette, so you can look at the example in the repo
- What’s tested:
- config options are all documented
- plugin hooks are documented
- views are all documented
- Cool use of parametrize to generate test cases based on introspection
- Nice use of fixtures
- Very cool idea
Luciana #4: PEP 673 — Self Type
- Heard from Brett Cannon that it has been accepted!
- Interesting for me as I’m learning more about types in Python
- Adds a way to annotate methods that return an instance of their class
- Particularly interesting for subclasses, exemple they gave:
from __future__ import annotations
class Shape:
def set_scale(self, scale: float) -> Shape: self.scale = scale return self class Circle(Shape): def set_radius(self, r: float) -> Circle: self.radius = r return self Circle().set_scale(0.5) # *Shape*, not Circle Circle().set_scale(0.5).set_radius(2.7) # => Error: Shape has no attribute set_radius
Extras
Luciana:
- Black is no longer in beta! Version 22.1.0 is out 🥳
- PyCascades 2022 reminder (remote!)
Joke: