Ensure basic interface compliance for an instance or dict of callables.
Checks that obj implements public methods of cls or has members listed in methods. If required is not supplied, implementing at least one interface method is sufficient. Methods present on obj that are not in the interface are ignored.
If obj is a dict and dict does not meet the interface requirements, the keys of the dictionary are inspected. Keys present in obj that are not in the interface will raise TypeErrors.
Raises TypeError if obj does not meet the interface criteria.
In all passing cases, an object with callable members is returned. In the simple case, obj is returned as-is; if dict processing kicks in then an anonymous class is returned.
Return an unordered sequence of all classes related to cls.
Traverses diamond hierarchies.
Fibs slightly: subclasses of builtin types are not returned. Thus class_hierarchy(class A(object)) returns (A, object), not A plus every class systemwide that derives from object.
Old-style classes are discarded and hierarchies rooted on them will not be descended.
If 'key' is present in dict 'kw', coerce its value to type 'type_' if necessary. If 'flexi_bool' is True, the string '0' is considered false when coercing to boolean.
decode a slice object as sent to __getitem__.
takes into account the 2.5 __index__() method, basically.
Decorates a function and issues a deprecation warning on use.
Given an instance or class, guess if it is or is acting as one of the basic collection types: list, set and dict. If the __emulates__ property is present, return that preferentially.
Given an iterator of which further sub-elements may also be iterators, flatten the sub-elements into a single iterator.
format_argspec_plus with considerations for typical __init__ methods
Wraps format_argspec_plus with error handling strategies for typical __init__ cases:
object.__init__ -> (self) other unreflectable (usually C) -> (self, *args, **kwargs)
Returns a dictionary of formatted, introspected function arguments.
A enhanced variant of inspect.formatargspec to support code generation.
Returns:
Example:
>>> format_argspec_plus(lambda self, a, b, c=3, **d: 123) {'args': '(self, a, b, c=3, **d)', 'self_arg': 'self', 'apply_kw': '(self, a, b, c=c, **d)', 'apply_pos': '(self, a, b, c, **d)'}
Return a function with a given __name__.
Will assign to __name__ and return the original function if possible on the Python implementation, otherwise a new function will be constructed.
Return the full set of inherited kwargs for the given cls.
Probes a class's __init__ method, collecting all named arguments. If the __init__ defines a **kwargs catch-all, then the constructor is presumed to pass along unrecognized keywords to it's base classes, and the collection process is repeated recursively on each of the bases.
inspect.getargspec with considerations for typical __init__ methods
Wraps inspect.getargspec with error handling for typical __init__ cases:
object.__init__ -> (self) other unreflectable (usually C) -> (self, *args, **kwargs)
iterate all the keys and attributes associated with a class, without using getattr().
Does not use getattr() so that class-sensitive descriptors (i.e. property.__get__()) are not called.
Automates delegation of __specials__ for a proxying type.
Decorates a function and issues a pending deprecation warning on use.
Assign a '_creation_order' sequence to the given instance.
This allows multiple instances to be sorted in order of creation (typically within a single thread; the counter is not particularly threadsafe).
Adjust the incoming callable such that a 'self' argument is not required.
Update a wrapper function to look like the wrapped function
wrapper is the function to be updated wrapped is the original function assigned is a tuple naming the attributes assigned directly from the wrapped function to the wrapper function (defaults to functools.WRAPPER_ASSIGNMENTS) updated is a tuple naming the attributes off the wrapper that are updated with the corresponding attribute from the wrapped function (defaults to functools.WRAPPER_UPDATES)
A set that considers only object id() for uniqueness.
This strategy has edge cases for builtin types- it's possible to have two 'foo' strings in one of these sets, for example. Use sparingly.
A dict that returns keys/values/items in the order they were added.
An object that maintains the order in which attributes are set upon it.
Also provides an iterator and a very basic getitem/setitem interface to those attributes.
(Not really a dict, since it iterates over values, not keys. Not really a list, either, since each value must have a key associated; hence there is no append or extend.)
A dict which populates missing values via a creation function.
Note the creation function takes a key, unlike collections.defaultdict.
A Registry that can store one or multiple instances of a single class on a per-thread scoped basis, or on a customized scope.
Appends items to a collection ensuring uniqueness.
Additional appends() of the same object are ignored. Membership is determined by identity (is a) not equality (==).
an weak-referencable, hashable collection which is strongly referenced until any one of its members is garbage collected.
A WeakKeyDictionary with an object identity index.
Adds a .by_id dictionary to a regular WeakKeyDictionary. Trades performance during mutation operations for accelerated lookups by id().
The usual cautions about weak dictionaries and iteration also apply to this subclass.
defaultdict(default_factory) --> dict with default factory
The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items.
Decorate a method memoize its return value.
Best applied to no-arg methods: memoization is not sensitive to argument values, and will always return the same value even when called with different arguments.
A read-only @property that is only evaluated once.
A constant symbol.
>>> symbol('foo') is symbol('foo') True >>> symbol('foo') <symbol 'foo>
A slight refinement of the MAGICCOOKIE=object() pattern. The primary advantage of symbol() is its repr(). They are also singletons.
Repeated calls of symbol('name') will all return the same instance.