An extension to PyProtocols to simplify the declaration of adapters.
A class advisor for declaring adapters.
- from_ (type or interface) – What the adapter adapts from, or a list of such types or interfaces (the ‘_’ suffix is used because ‘from’ is a Python keyword).
- to (type or interface) – What the adapter adapts to, or a list of such types or interfaces.
- factory (callable) – An (optional) factory for actually creating the adapters. This is any callable that takes a single argument which is the object to be adapted. The factory should return an adapter if it can perform the adaptation and None if it cannot.
- cached (bool) – Should the adapters be cached? If an adapter is cached, then the factory will produce at most one adapter per instance.
- when (str) – A Python expression that selects which instances of a particular type can be adapted by this factory. The expression is evaluated in a namespace that contains a single name adaptee, which is bound to the object to be adapted (e.g., ‘adaptee.is_folder’).
whenarguments are ignored if