Posts tagged “Python”
6 posts Subscribe by RSS
6 posts
Python attribute lookup order: why a data descriptor beats the instance __dict__, and when __set_name__ runs
obj.x checks data descriptors before the instance __dict__. How __set__ or __delete__ sets the order, why cached_property can be overwritten, and why late-added descriptors miss __set_name__.
Where does a Python generator's return value go? StopIteration.value and PEP 479
A generator's return value never shows up in a for loop; it rides on StopIteration.value. How yield from gets it, why StopIteration in a generator becomes RuntimeError, and what close() returns.
How a Python with block swallows exceptions: __exit__ return values and return in finally
When __exit__ returns a true value, the with statement suppresses the exception. How that differs from return in finally, and how to write a suppressor that catches only what you mean.
Why L=[] as a Python default argument keeps growing: defaults are built once, at def time
Call def f(a, L=[]) three times and the list keeps growing. What the Python docs say about when defaults are evaluated, __defaults__, the None pattern and dataclass default_factory.
Topological Sort and Cycle Detection: Ordering by In-Degree and Finding What Got Stuck
Implement topological sort by counting in-degrees, see what is left over when the graph has a cycle, and learn how Python's graphlib TopologicalSorter and CycleError behave.
When does Python rebuild a .pyc? Timestamp vs hash-based invalidation
By default CPython trusts a .pyc if the source's mtime and size match. When that misses edits, how checked-hash and unchecked-hash pycs differ, and how to use compileall (Python 3.14.8 docs).
No posts match. Try another word.