Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 1.64 KB

File metadata and controls

34 lines (27 loc) · 1.64 KB

Prebound Method — where it lives outside this repo

Cited, real implementations to study (or point an agent at) when designing or reviewing module-API code.

Python standard library

  • random. The flagship: random.random, random.seed, and friends are bound methods of one hidden Random() built at import, and random.Random stays public for isolated streams. docs.python.org/3/library/random.html · source
  • secrets. choice and randbits are prebound from a module-level SystemRandom instance — the same wiring with a different engine. (The useful contrast: token_hex/token_bytes are plain module functions that merely call it — they have no __self__ and would fail this unit's own shares_instance() check.) docs.python.org/3/library/secrets.html
  • calendar. Module functions like calendar.month delegate to a module-level TextCalendar instance. source

The chapter

What to notice across all of them

Every stdlib example keeps both doors open: the convenient module functions for the common case, the public class for isolation. When reviewing a module-level API over shared state, check for the second door — its absence is tomorrow's monkeypatch.