Standard Search
About 14 results
https://rednafi.com/python/typing-override/ · 6 Nov 2024
Catch method override errors at type-check time with Python's @override decorator from PEP 698, preventing typos and signature mismatches.
https://rednafi.com/python/typeguard-vs-typeis/ · 27 Apr 2024
Understand TypeIs vs TypeGuard in Python: TypeIs provides more intuitive type narrowing by narrowing both positive and negative branches.
https://rednafi.com/python/annotate-args-and-kwargs/ · 8 Jan 2024
Properly annotate Python *args and **kwargs with heterogeneous types using Unpack, TypedDict, and modern type hints from PEP-692.
https://rednafi.com/python/statically-enforcing-frozen-dataclasses/ · 4 Jan 2024
Enforce immutable dataclasses at type-check time with @final decorator to catch mutations before runtime without frozen=True performance cost.
https://rednafi.com/typescript/guard-clauses-and-never-type/ · 22 May 2022
Master TypeScript's never type and Python's NoReturn for exhaustiveness checking. Flatten nested conditionals with guard clauses for cleaner code.
https://rednafi.com/python/declarative-payloads-with-typedict/ · 11 Mar 2022
Use Python TypedDict to declaratively define API payload structures. Get type safety for nested dictionaries and improve code maintainability.
https://rednafi.com/python/self-type/ · 28 Feb 2022
Use Python's Self type from PEP 673 to annotate methods returning class instances, eliminating complex forward references and TypeVars.
https://rednafi.com/python/type-guard/ · 23 Feb 2022
Use Python's TypeGuard to create custom type narrowing functions that help static type checkers understand runtime type checks and validations.
https://rednafi.com/python/why-noreturn-type-exists/ · 21 Feb 2022
Use Python's NoReturn type to annotate functions that never return normally, helping type checkers understand exception-raising and infinite loop code.
https://rednafi.com/python/go-rusty-with-exception-handling/ · 2 Feb 2022
Implement Rust-style Result types for type-safe exception handling in Python using generic Ok and Err types inspired by Black formatter.