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.
Dictionary with ‘squishy’ removal of least recently used items.
tuple() subclass that adds labeled names.
Is also pickleable.
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 (==).
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.
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.
A decorator that behaves like @property except that operates on classes rather than instances.
This is helpful when you need to compute __table_args__ and/or __mapper_args__ when using declarative.
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.
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.
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.
Decorates a function and issues a pending deprecation warning on use.
Turn an instancemethod into a (parent, name) pair to produce a serializable callable.
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).
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.