Python Type Hints - How to Avoid “The Boolean Trap” by Adam Johnson

Python Type Hints - How to Avoid “The Boolean Trap” by Adam Johnson

Articles

“The Boolean Trap” is a programming anti-pattern where a boolean argument switches behaviour, leading to confusion. In this post we’ll look at the trap in more detail, and several ways to avoid it in Python, with added safety from type hints.