Routines to help with the creation, loading and introspection of modules, classes, hierarchies, attributes, functions, and methods.
Class | classproperty |
A decorator that behaves like @property except that operates on classes rather than instances. |
Class |
|
Apply translation of functions to accept \**kw arguments if they don't already. |
Class | generic |
Descriptor which proxies a function when the attribute is not present in dict |
Class |
|
A mixin class that maintains the names of memoized elements in a collection for easy cache clearing, generative, etc. |
Class | hybridmethod |
Decorate a function as cls- or instance- level. |
Class | hybridproperty |
Undocumented |
Class |
|
Apply memoized items to an object using a __getattr__ scheme. |
Class |
|
Undocumented |
Class | portable |
Turn an instancemethod into a (parent, name) pair to produce a serializable callable. |
Class | rw |
Undocumented |
Class | safe |
Reraise an exception after invoking some handler code. |
Class | symbol |
A constant symbol. |
Class |
|
A mixin class that marks a class as 'typing only', meaning it has absolutely no methods, attributes, or runtime functionality whatsoever. |
Function | add |
Undocumented |
Function | as |
Ensure basic interface compliance for an instance or dict of callables. |
Function | asbool |
Undocumented |
Function | asint |
Coerce to integer. |
Function | assert |
Undocumented |
Function | attrsetter |
Undocumented |
Function | bool |
Return a callable that will evaluate a string as boolean, or one of a set of "alternate" string values. |
Function | chop |
Chop extraneous lines off beginning and end of a traceback. |
Function | class |
Return an unordered sequence of all classes related to cls. |
Function | clsname |
Undocumented |
Function | coerce |
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. |
Function | constructor |
Instantiate cls using the __dict__ of obj as constructor arguments. |
Function | constructor |
Produce a tuple structure that is cacheable using the __dict__ of obj to retrieve values |
Function | counter |
Return a threadsafe counter function. |
Function | create |
A class decorator indicating attributes should refer to a proxy class. |
Function | decode |
decode a slice object as sent to __getitem__. |
Function | decorator |
A signature-matching decorator factory. |
Function | dictlike |
Return a (key, value) iterator for almost any dict-like object. |
Function | duck |
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. |
Function | ellipses |
Undocumented |
Function | format |
format_argspec_plus with considerations for typical __init__ methods |
Function | format |
Returns a dictionary of formatted, introspected function arguments. |
Function | generic |
Produce a __repr__() based on direct association of the __init__() specification vs. same-named attributes present. |
Function | get |
Undocumented |
Function | get |
Return the argument signature for any callable. |
Function | get |
Return the full set of inherited kwargs for the given `cls`. |
Function | get |
Return the set of legal kwargs for the given `func`. |
Function | getargspec |
inspect.getargspec with considerations for typical __init__ methods |
Function | has |
Undocumented |
Function | inject |
Undocumented |
Function | inject |
Undocumented |
Function | iterate |
iterate all the keys and attributes associated with a class, without using getattr(). |
Function | map |
Call the given function given each nonzero bit from n. |
Function | md5 |
Undocumented |
Function | memoized |
Decorate a method memoize its return value. |
Function | method |
Return True if the two class methods don't match. |
Function | methods |
Return True if the two methods are the same implementation. |
Function | monkeypatch |
Automates delegation of __specials__ for a proxying type. |
Function | only |
Decorate the given function to be a no-op after it is called exactly once. |
Function | parse |
Given a user parameter, parse the parameter into a chosen value from a list of choice objects, typically Enum values. |
Function | quoted |
Parse a dotted identifier with accommodation for quoted names. |
Function | repr |
Trims a list of strings from the middle and return a string of up to four elements. Strings greater than 11 characters will be truncated |
Function | set |
Assign a '_creation_order' sequence to the given instance. |
Function | string |
Undocumented |
Function | tag |
Undocumented |
Function | unbound |
Adjust the incoming callable such that a 'self' argument is not required. |
Function | walk |
Undocumented |
Function | warn |
Issue a warning. |
Function | warn |
executes the given function, catches all exceptions and converts to a warning. |
Function | warn |
Issue a warning with a parameterized string, limiting the number of registrations. |
Function | wrap |
Augment functools.update_wrapper() to work with objects with a ``__call__()`` method. |
Variable |
|
Undocumented |
Class | _ |
An 'IntFlag' copycat that isn't slow when performing bitwise operations. |
Class | _hash |
A string subclass that can only be hashed on a maximum amount of unique values. |
Class | _ |
Undocumented |
Class | _memoized |
A read-only @property that is only evaluated once. |
Class | _non |
a plain descriptor that proxies a function. |
Function | _dedent |
Undocumented |
Function | _exec |
Undocumented |
Function | _inspect |
Undocumented |
Function | _unique |
Undocumented |
Function | _update |
given a FullArgSpec, convert defaults to be symbol names in an env. |
Function | _warnings |
Undocumented |
Constant | _SQLA |
Undocumented |
Constant | _UNITTEST |
Undocumented |
Type Variable | _E |
Undocumented |
Type Variable | _F |
Undocumented |
Type Variable | _ |
Undocumented |
Type Variable | _GFD |
Undocumented |
Type Variable | _HM |
Undocumented |
Type Variable | _HP |
Undocumented |
Type Variable | _MA |
Undocumented |
Type Variable | _MP |
Undocumented |
Type Variable | _PF |
Undocumented |
Type Variable | _T |
Undocumented |
Type Variable | _ |
Undocumented |
Type Variable | _TE |
Undocumented |
Variable | _creation |
Undocumented |
Variable | _not |
Undocumented |
Variable | _param |
Undocumented |
Variable | _warning |
Undocumented |
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. obj A type, instance, or dictionary of callables. cls Optional, a type. All public methods of cls are considered the interface. An ``obj`` instance of cls will always pass, ignoring ``required``.. methods Optional, a sequence of method names to consider as the interface. required Optional, a sequence of mandatory implementations. If omitted, an ``obj`` that provides at least one interface method is considered sufficient. As a convenience, required may be a type, in which case all public methods of the type are required.
Any
, argtype: Union[ Tuple[ Type[ Any], ...], Type[ Any]]
, name: str
) -> Any
:
(source)
¶
Undocumented
Return a callable that will evaluate a string as boolean, or one of a set of "alternate" string values.
List[ str]
, exclude_prefix: re.Pattern[ str]
= _UNITTEST_RE, exclude_suffix: re.Pattern[ str]
= _SQLA_RE) -> List[ str]
:
(source)
¶
Chop extraneous lines off beginning and end of a traceback. :param tb: a list of traceback lines as returned by ``traceback.format_stack()`` :param exclude_prefix: a regular expression object matching lines to skip at beginning of ``tb`` :param exclude_suffix: a regular expression object matching lines to skip at end of ``tb``
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.
Dict[ str, Any]
, key: str
, type_: Type[ Any]
, flexi_bool: bool
= True, dest: Optional[ Dict[ str, Any]]
= None):
(source)
¶
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.
Instantiate cls using the __dict__ of obj as constructor arguments. Uses inspect to match the named arguments of ``cls``.
Type[ Any]
, target_cls_sphinx_name: str
, proxy_cls_sphinx_name: str
, classmethods: Sequence[ str]
= (), methods: Sequence[ str]
= (), attributes: Sequence[ str]
= ()) -> Callable[ [ _T], _T]
:
(source)
¶
A class decorator indicating attributes should refer to a proxy class. This decorator is now a "marker" that does nothing at runtime. Instead, it is consumed by the tools/generate_proxy_methods.py script to statically generate proxy methods and attributes that are fully recognized by typing tools such as mypy.
decode a slice object as sent to __getitem__. takes into account the 2.5 __index__() method, basically.
Any
, default: Optional[ Type[ Any]]
= None) -> Optional[ Type[ Any]]
:
(source)
¶
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.
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)
Union[ Callable[ ..., Any], compat.FullArgSpec]
, grouped: bool
= True) -> Dict[ str, Optional[ str]]
:
(source)
¶
Returns a dictionary of formatted, introspected function arguments. A enhanced variant of inspect.formatargspec to support code generation. fn An inspectable callable or tuple of inspect getargspec() results. grouped Defaults to True; include (parens, around, argument) lists Returns: args Full inspect.formatargspec for fn self_arg The name of the first positional argument, varargs[0], or None if the function defines no positional arguments. apply_pos args, re-written in calling rather than receiving syntax. Arguments are passed positionally. apply_kw Like apply_pos, except keyword-ish args are passed as keywords. apply_pos_proxied Like apply_pos but omits the self/cls argument Example:: >>> format_argspec_plus(lambda self, a, b, c=3, **d: 123) {'grouped_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)'}
Any
, additional_kw: Sequence[ Tuple[ str, Any]]
= (), to_inspect: Optional[ Union[ object, List[ object]]]
= None, omit_kwarg: Sequence[ str]
= ()) -> str
:
(source)
¶
Produce a __repr__() based on direct association of the __init__() specification vs. same-named attributes present.
Callable[ ..., Any]
, no_self: bool
= False, _is_init: bool
= False) -> compat.FullArgSpec
:
(source)
¶
Return the argument signature for any callable. All pure-Python callables are accepted, including functions, methods, classes, objects with __call__; builtins and other edge cases like functools.partial() objects raise a TypeError.
type
, *, _set: Optional[ Set[ str]]
= None, raiseerr: Literal[ True]
= ...) -> Set[ str]
:type
, *, _set: Optional[ Set[ str]]
= None, raiseerr: bool
= False) -> Optional[ Set[ str]]
: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 its base classes, and the collection process is repeated recursively on each of the bases. Uses a subset of inspect.getfullargspec() to cut down on method overhead, as this is used within the Core typing system to create copies of type objects which is a performance-sensitive operation. No anonymous tuple arguments please !
Return the set of legal kwargs for the given `func`. Uses getargspec so is safe to call for methods, functions, etc.
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)
Optional[ str]
, injecttext: str
, pos: int
) -> str
:
(source)
¶
Undocumented
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.
Union[ Type[ Any], object]
, against_method: Callable[ ..., Any]
) -> bool
:
(source)
¶
Return True if the two class methods don't match.
Automates delegation of __specials__ for a proxying type.
Callable[ ..., _T]
, retry_on_exception: bool
) -> Callable[ ..., Optional[ _T]]
:
(source)
¶
Decorate the given function to be a no-op after it is called exactly once.
Any
, choices: Dict[ _E, List[ Any]]
, name: str
, resolve_symbol_names: bool
= False) -> Optional[ _E]
:
(source)
¶
Given a user parameter, parse the parameter into a chosen value from a list of choice objects, typically Enum values. The user argument can be a string name that matches the name of a symbol, or the symbol object itself, or any number of alternate choices such as True/False/ None etc. :param arg: the user argument. :param choices: dictionary of enum values to lists of possible entries for each. :param name: name of the argument. Used in an :class:`.ArgumentError` that is raised if the parameter doesn't match any available argument.
Parse a dotted identifier with accommodation for quoted names. Includes support for SQL-style double quotes as a literal character. E.g.:: >>> quoted_token_parser("name") ["name"] >>> quoted_token_parser("schema.name") ["schema", "name"] >>> quoted_token_parser('"Schema"."Name"') ['Schema', 'Name'] >>> quoted_token_parser('"Schema"."Name""Foo"') ['Schema', 'Name""Foo']
Trims a list of strings from the middle and return a string of up to four elements. Strings greater than 11 characters will be truncated
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).
str
, category: Type[ Warning]
) -> Callable[ [ _F], _F]
:
(source)
¶
Undocumented
Augment functools.update_wrapper() to work with objects with a ``__call__()`` method. :param fn: object with __call__ method
Union[ str, types.CodeType]
, env: Dict[ str, Any]
, fn_name: str
) -> Callable[ ..., Any]
:
(source)
¶
Undocumented