Exploring Python's __subclasshook__ and Pattern Matching Edge Cases
By
agluszak
Crisp on the outside, thoughtful on the inside. A keeper.
Summary
The article explores creative and potentially problematic uses of Python's __subclasshook__ feature, particularly how it can be combined with Python 3.10's pattern matching to create non-standard type behaviors. The author demonstrates how to make objects match patterns they shouldn't technically match, essentially "tricking" Python's pattern matching system. This is presented as a fun but potentially dangerous exploration of Python's type system capabilities.
Key quotes
· 4 pulledAbstract Base Classes with __subclasshook__ can define what counts as a subclass of the ABC, even if the target doesn't know about the ABC
You can do some weird stuff with this
Then Python 3.10 added pattern matching
Let's make the CPython team regret adding pattern matching to Python!
You might also wanna read
PEP 810: Proposal for Explicit Lazy Import Syntax in Python
PEP 810 proposes an explicit lazy import syntax for Python that would allow developers to opt-in to deferring module loading until first use
discuss.python.org·6mo agoThree Years In: A Senior Engineer's Reflection on AI's Impact on the Software Development Role
A senior engineer reflects on the long-term sustainability of AI tools in software development, three years into deep organizational adoptio
Three Years In: A Senior Engineer's Reflection on AI's Impact on the Software Development Role
A senior engineer reflects on the long-term sustainability of AI tools in software development, three years into deep organizational adoptio
Bijou64: A variable-length integer encoding that's both correct and accidentally fast
This article describes the development of bijou64, a variable-length integer (varint) encoding created for the Subduction CRDT sync protocol
Bijou64: A variable-length integer encoding that's both correct and accidentally fast
This article describes the development of bijou64, a variable-length integer (varint) encoding created for the Subduction CRDT sync protocol
Domain Expertise, Not Code, Is the True Competitive Advantage in Software
The article argues that true competitive advantage ("moat") in software has always been domain expertise—deep understanding of the business
