π¦ ClawHub
Python
by @ivangdavila
Write reliable Python avoiding mutable defaults, import traps, and common runtime surprises.
TERMINAL
clawhub install pyπ About This Skill
name: Python slug: python version: 1.0.1 description: Write reliable Python avoiding mutable defaults, import traps, and common runtime surprises. metadata: {"clawdbot":{"emoji":"π","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}}
Quick Reference
| Topic | File |
|-------|------|
| Dynamic typing, type hints, duck typing | types.md |
| List/dict/set gotchas, comprehensions | collections.md |
| Args/kwargs, closures, decorators, generators | functions.md |
| Inheritance, descriptors, metaclasses | classes.md |
| GIL, threading, asyncio, multiprocessing | concurrency.md |
| Circular imports, packages, __init__.py | imports.md |
| Pytest, mocking, fixtures | testing.md |
Critical Rules
def f(items=[]) shares list across all calls β use items=None then items = items or []is checks identity, == checks equality β "a" * 100 is "a" * 100 may be Falsefor x in list(items):except: catches SystemExit and KeyboardInterrupt β use except Exception:UnboundLocalError when assigning to outer scope variable β use nonlocal or globalopen() without context manager leaks handles β always use with open():0.1 + 0.2 != 0.3 β floating point, use decimal.Decimal for moneyitertools.tee__init__ instead__init__ is not constructor β __new__ creates instance, __init__ initializesencoding='utf-8'