#242: from lib import * but less
Published Thu, Jul 15, 2021,
recorded Thu, Jul 15, 2021
Watch the live stream:
About the show
Sponsored by us:
- Check out the courses over at Talk Python
- And Brian’s book too!
Special guest: Al Sweigart
Brian #1: just
- From a tweet by Jeff Triplett
- “
just
is a handy way to save and run project-specific commands. - Commands, called recipes, are stored in a file called
justfile
with syntax inspired bymake
- Just is a command runner, not a build system, so it avoids much of Make’s complexity and idiosyncrasies. No need for .PHONY recipes!
- Linux, MacOS, and Windows are supported with no additional dependencies.”
- It’s written in Rust.
- My favorite differences:
- a couple spaces is fine, no need for tabs
- Recipes can accept command line arguments
- Recipes can be listed from the command line.
- Recipes can be written in arbitrary languages,
like Python hello: echo "Hello World!" pyhello: #!/usr/bin/env python3 print('Hello from python!')
Michael #2: Strong Typing
- via Roman Right (Beanie)
- Decorator which checks whether the function is called with the correct type of parameters.
- Decorator which checks at Runtime whether the function is called with the correct type of parameters.
- Raises TypeMisMatch if the used parameters in a function call where invalid.
Al #3:
- New book: “The Big Book of Small Python Projects”
- New book: “Beyond the Basic Stuff with Python”
Brian #4: testbook
- Suggested by David Nicholson
- Write conventional unit tests for Jupyter Notebooks
- Execute all or some specific cells before unit test
- Share kernel context across multiple tests (using pytest fixtures)
- Support for patching objects
- Inject code into Jupyter notebooks
- Works with any unit testing library, unittest, pytest, etc.
example
foo.ipynb
:def foo(a, b): return a + b
test_foo.py
:from testbook import testbook @testbook('foo.ipynb', execute=True) def test_foo(tb): foo = tb.ref("foo") assert foo(1, 2) == 3
Michael #5: auto-all
- Automatically manage the __all__ variable in Python modules.
- Easily populate the
__all__
variable in modules. - Easily exclude imported objects
- Clearly differentiate between internal and external facing objects.
- Use simple, intuitive code.
- Never worry about forgetting to add new objects to
__all__
. - Help Python IDE's differentiate between internal and external facing objects.
- Easily populate the
- Can use “regions” via
start_all()
andend_all()
- I prefer the decorator (functions only, seems ripe for a PR for classes)
@public def a_public_function(): pass
Al #6:
- Next book: Untitled Recursion Book
Extras
Michael:
- OhMyPosh + auto env
- A scalable method of determining physiological endotypes of sleep apnea from a polysomnographic sleep study
- Email, inbox woes, and catching up
- Microsoft unveils Windows 365
- Facebook and its advertisers are ‘panicking’ as the majority of iPhone users opt out of tracking
Al