python-duck-typing
- Python code style that encourages you to care about what an object is capable of rather than what it is
- As in, if it walks like a duck and quacks like a duck, for all intents and purposes, itβs a duck
- So, donβt care about the type; care about the behavior (its traits)
- Can it quack?
- Can it fly?
- Instead of βis it a duck?β
- Is this in opposition to static typing (which defines what things are)?
- Does not mean LBYL by checking if it can quack/fly (e.g.
if hasattr(thing, 'quack')
)
- Instead, just try to make it quack and handle failure if it occurs