Sadra Yahyapourblog.imsadra.me·Nov 3, 2024FeaturedGeneric Typing in PythonSince Python introduced the ability to add generic types to functions, the language has become much more type-friendly and encourages you to follow this convention for more maintainable code. Obviously, this will lead to a better development experien...31 likes·944 readsPython Generics
JP Hutchinsblog.jphutchins.com·Oct 14, 2024Python: Generic Request -> Response ProtocolIs 100% static type coverage practical when datatypes represent communication with a remote resource? If you are implementing a protocol that defines a Response (or Error) Type for every Request, it may seem like lots of code will be written just to ...1 like·58 readsPython
Lucy Linderblog.derlin.ch·Jul 10, 2023When plans go astray: my unsuccessful journey of migrating a large Django project to MypyTL;DR - Mypy is amazing, but your code needs to be ready for it. The untyped nature of Python allows magic to happen and shortcuts to be made (at the cost of more runtime errors). Adding a type checker such as Mypy to a codebase developed under this ...2 likes·2.2K readsPython
Marcel Jackwerthblog.mrcljx.dev·Jan 26, 2023Exhaustive Checks with MypyIf you want to exhaustively check an enum (or a literal) and have Mypy tell you when you forgot a case, you can write yourself a tiny utility function: from typing import NoReturn def unreachable(v: NoReturn) -> NoReturn: raise AssertionError() ...38 readsPython