Be fr. Do you really think Sifuna & team are incapable of putting together a manifesto, an impressive one at that?
Constitutionalism is not a fallback position. It is a deliberate distillation of much broader objectives into a principle that is easily understood and widely
Every exception is a class, so except AppError also catches ValidationError if it inherits from it. Clauses are checked in order and the first match wins, same as MRO. Put specific ones before general ones.
Every exception is a class, so except AppError also catches ValidationError if it inherits from it. Clauses are checked in order and the first match wins, same as MRO. Put specific ones before general ones.
CPython internals: exceptions.
try/except/else/finally: else runs only if no error happened, and unlike code at the end of try, it isn’t covered by the except clauses. finally runs no matter what.
#Python#CPython#100DaysOfCode
so c.area runs it with no parentheses and always reflects the current data. With no setter, assigning to it raises AttributeError.
@classmethod passes the class itself as cls, handy for alternate constructors. @staticmethod passes nothing, so it’s just a plain function
CPython internals: @contextmanager.
You can write a context manager as a generator instead of a class. Code before yield plays __enter__, the with block runs while the generator is paused, and code after yield plays __exit__.
#Python#CPython#100DaysOfCode
The catch: if the block raises an error, it’s thrown into the generator at the yield, so the code after it never runs. Wrap the yield in try/finally to guarantee cleanup, which a class-based __exit__ gets for free.
CPython internals: @contextmanager.
You can write a context manager as a generator instead of a class. Code before yield plays __enter__, the with block runs while the generator is paused, and code after yield plays __exit__.
#Python#CPython#100DaysOfCode
CPython internals: context managers and the with statement.
with calls __enter__ when the block starts and __exit__ when it ends, whether the block finished normally or raised an error.
#Python#CPython#100DaysOfCode
That’s why with open(...) always closes the file: the file’s own __exit__ does it, at a fixed point you can see in the code.
The part that surprised me is that __exit__ decides what happens to the error. Return False and the error keeps going. Return True and it’s swallowed.
CPython internals: context managers and the with statement.
with calls __enter__ when the block starts and __exit__ when it ends, whether the block finished normally or raised an error.
#Python#CPython#100DaysOfCode
UnboundLocalError (it's a compile time scan, not a runtime search), and being precise that print() always uses __str__ once it's defined, not a memory address.
Good to confirm the foundation is solid before building further.
#Python#CPython#100DaysOfCode
Spent today rebuilding everything learned so far in this CPython internals deep dive, from bytecode through multiple inheritance, 15 topics, explained from scratch and proven in code, no notes.
A few soft spots surfaced and got fixed properly: the exact mechanism behind