About 149 results
https://rednafi.com/python/limit-concurrency-with-semaphore/ · 10 Feb 2022
Control concurrent async requests with Python asyncio.Semaphore to respect rate limits and prevent overwhelming APIs or services.
https://rednafi.com/python/amphibian-decorators/ · 6 Feb 2022
Build Python decorators that work seamlessly with both sync and async functions using inspect.iscoroutinefunction for maximum flexibility.
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.
https://rednafi.com/python/variance-of-generic-types/ · 31 Jan 2022
Understand covariance, contravariance, and invariance in Python generics with practical examples of type relationships and subtyping rules.
https://rednafi.com/python/create-sub-dict/ · 30 Jan 2022
Optimize Python dictionary slicing from O(DK) to O(K) complexity using direct key lookups instead of iterating through all items.
https://rednafi.com/python/early-bound-function-defaults/ · 27 Jan 2022
Avoid Python function default argument pitfalls caused by early binding, where mutable defaults and function calls bind at definition time.
https://rednafi.com/python/use-assertis-to-check-literal-booleans/ · 24 Jan 2022
Test literal booleans correctly in Python unittest using assertIs instead of assertTrue/assertFalse to avoid truthy/falsy confusion.
https://rednafi.com/python/static-typing-decorators/ · 23 Jan 2022
Type Python decorators accurately using ParamSpec and Concatenate to preserve wrapped function signatures and enable proper static analysis.
https://rednafi.com/python/inspect-docstring-with-pydoc/ · 22 Jan 2022
View Python docstrings from the command line with pydoc or serve them as HTML documentation for modules, classes, and functions.
https://rednafi.com/python/check-is-a-power-of-two/ · 21 Jan 2022
Use Python's bit_count() method to elegantly check if an integer is a power of two by counting on-bits in binary representation.