Python 3.8 Final Types, Packaging with Flit and Unit Tests

·33m 18s
Shared point

Python News and Tooling

Type Annotations and PEP 591

This episode dives into the introduction of the final type annotation in Python 3.8 via PEP 591. This addition provides a powerful mechanism to indicate that a class or a method should not be overridden, or that a variable is intended to be a constant. While this acts as static analysis rather than runtime behavior, it empowers developers using type checkers to catch hierarchy errors during the development lifecycle.

Modern Packaging with Flit

Discussing the evolution of Python project management, the hosts explore the release of Flit 2. Key highlights include:
• Simplified project initiation comparable to npm init.
• Enhanced support for source directories, resolving previous limitations.
• Increased flexibility for working outside of Git repositories.
• Improved user experience by making metadata items like email addresses optional.

Handling Units with Pint

For projects involving physical measurements, the Pint library is highly recommended. It allows developers to:
• Attach units to numeric values to ensure calculations are physically meaningful.
• Perform seamless math operations between differing units (e.g., adding meters and inches).

"The MCO Mission Investigation Board has determined the root cause for the loss of the MCO spacecraft was a failure to use metric units... specifically, the thruster performance data in English units instead of metric units was used."

Testing and Frameworks

PyTest Plugins

Brian highlights a curated list of eight PyTest plugins, including:
PyTest-Sugar: For improved output readability and instant failure reporting.
PyTest-Picked: A smart tool that runs tests related to files modified in your current branch.
PyTest-XDist: Essential for parallel test execution across multiple processes or machines.

Web Framework Ecosystem

Michael provides a whirlwind tour of the blossoming ASGI and async/await enabled web landscape. The list covers established names like Sanic and Starlet, as well as feature-rich options like FastAPI—which leverages type hints for modern API development—and Cort, a drop-in replacement for Flask that adds asynchronous capabilities.

Best Practices for Exceptions

Finally, the episode highlights the importance of raising more meaningful exceptions. The hosts advocate for passing additional diagnostic data as arguments to exception constructors, rather than burying critical information inside a single string message.

Topics

Chapters

6 chapters
Python Bytes
AI chat — answers grounded in episodes