Writing Python like it's Rust

Maor Kadosh Maor Kadosh
Language: Hebrew
The presentation was given on 2025.07.27 at PyWeb in July 2025 at NymHealth in Tel Aviv.

The talk will be based on this blog post, that finally aggregated all of my favorite methods of describing business logic in Python.

Python's bolted-on typing notation has recently evolved enough to the point of being able to resemble the type system of the ML family (Meta Language, not Machine Learning 😜) and thus the wonderful workflow of Rust and its OCaml roots.

I will provide examples from real-life code that I wrote utilizing these tricks to catch bugs before the program even started. But more importantly, I'll talk about the killer feature of this method (that's not mentioned in the article), that for some reason went completely under the radar: Pyright's reportMatchNotExhaustive check, which is off by default.

This behaviour (getting a pre-runtime warning for unhandled cases) is also achievable with abc.ABC + abc.abstractmethod. Using reportMatchNotExhaustive allows you to carry this feature to Functional Land, which I think is getting popular recently with the rise of Pydantic and FastAPI.