Utilities used in vm.py.
Class |
|
Undocumented |
Class |
|
Track return state for try/except/finally blocks. |
Class |
|
A visitor that finds type comments that will be ignored. |
Function | adjust |
Adjust line numbers for return statements in with blocks. |
Function | build |
Undocumented |
Function | build |
Merge a list of kw dicts into a single dict. |
Function | call |
Map a binary operator to "magic methods" (__add__ etc.). |
Function | call |
Try to call a method like __iadd__, possibly fall back to __add__. |
Function | check |
Undocumented |
Function | copy |
Create a copy of the input dict with some keys deleted. |
Function | ensure |
Unpack starargs if it has not been done already. |
Function | get |
Undocumented |
Function | get |
Gets a detailed error message for [name-error]. |
Function | jump |
Implementation of various _JUMP_IF bytecodes. |
Function | load |
Retrieve the value out of a closure cell. |
Function | log |
Write a multi-line log message, including backtrace and stack. |
Function | make |
Create a class with the name, bases and methods given. |
Function | make |
Create a function or closure given the arguments. |
Function | match |
Pick attributes out of a class instance for pattern matching. |
Function | match |
Pick values out of a mapping for pattern matching. |
Function | match |
See if var is a map for pattern matching. |
Function | match |
See if var is a sequence for pattern matching. |
Function | merge |
Undocumented |
Function | pop |
Pop count iterables off the stack and concatenate. |
Function | process |
Modifies annotations from a function type comment. |
Function | push |
Undocumented |
Function | to |
Convert any awaitables and generators in obj to coroutines. |
Function | unpack |
Undocumented |
Function | unpack |
Unpack an iterable. |
Function | update |
Update the excluded_types attribute of functions in the current frame. |
Variable | log |
Undocumented |
Class | _ |
Undocumented |
Class | _ |
Base class for detailed name error messages. |
Class | _ |
Undocumented |
Class | _ |
Name error details for a name defined in an outer class. |
Class | _ |
Name error details for a name defined in an outer function. |
Function | _base |
Undocumented |
Function | _binding |
Helper for _to_coroutine. |
Function | _call |
Call a binary operator on two cfg.Binding objects. |
Function | _check |
Check parameter defaults against annotations. |
Function | _check |
Check if the new class overrides a final attribute or method. |
Function | _convert |
Undocumented |
Function | _expand |
Expand Protocol[T, ...] to Protocol, Generic[T, ...]. |
Function | _filter |
Process the temporary classes created by six.with_metaclass. |
Function | _get |
Extract an annotation from terms in `a | b | ...`. |
Function | _get |
Gets the class or function objects for a sequence of nested scope names. |
Function | _maybe |
Attempt to evaluate a '|' operation as a typing.Union. |
Function | _merge |
Merge a set of heterogeneous tuples from var's bindings. |
Function | _module |
Undocumented |
Function | _overrides |
Check whether subcls_var overrides or newly defines the given attribute. |
Function | _process |
Process a base class for InterpreterClass creation. |
Function | _var |
Undocumented |
Function | _var |
Undocumented |
Constant | _FUNCTION |
Undocumented |
Constant | _TRUNCATE |
Undocumented |
Constant | _TRUNCATE |
Undocumented |
Variable | _repr |
Undocumented |
cfg.Variable
, keys_var: cfg.Variable
, ctx) -> cfg.Variable
:
(source)
¶
Create a copy of the input dict with some keys deleted.
Implementation of various _JUMP_IF bytecodes. Args: state: Initial FrameState. op: An opcode. ctx: The current context. pop: True if a value is popped off the stack regardless. jump_if_val: True or False (indicates which value will lead to a jump). or_pop: True if a value is popped off the stack only when the jump is not taken. Returns: The new FrameState.
Retrieve the value out of a closure cell. Used to generate the 'closure' tuple for MAKE_CLOSURE. Each entry in that tuple is typically retrieved using LOAD_CLOSURE. Args: state: The current VM state. op: The opcode. op.arg is the index of a "cell variable": This corresponds to an entry in co_cellvars or co_freevars and is a variable that's bound into a closure. check_bindings: Whether to check the retrieved value for bindings. ctx: The current context. Returns: A new state.
Create a class with the name, bases and methods given. Args: node: The current CFG node. props: class_mixin.ClassBuilderProperties required to build the class ctx: The current context. Returns: A node and an instance of class_type.
Create a function or closure given the arguments.
cfg.Variable
, cls_var: cfg.Variable
, keys_var: cfg.Variable
, posarg_count: int
, ctx) -> ClassMatch
:
(source)
¶
Pick attributes out of a class instance for pattern matching.
cfg.Variable
, keys_var: cfg.Variable
, ctx) -> Optional[ cfg.Variable]
:
(source)
¶
Pick values out of a mapping for pattern matching.
Modifies annotations from a function type comment. Checks if a type comment is present for the function. If so, the type comment is used to populate annotations. It is an error to have a type comment when annotations is not empty. Args: node: The current node. op: An opcode (used to determine filename and line number). func: An abstract.InterpreterFunction. ctx: The current context.
Convert any awaitables and generators in obj to coroutines. Implements the GET_AWAITABLE opcode, which returns obj unchanged if it is a coroutine or generator and otherwise resolves obj.__await__ (https://docs.python.org/3/library/dis.html#opcode-GET_AWAITABLE). So that we don't have to handle awaitable generators specially, our implementation converts generators to coroutines. Args: state: The current state. obj: The object, a cfg.Variable. top: Whether this is the top-level recursive call, to prevent incorrectly recursing into the result of obj.__await__. ctx: The current context. Returns: A tuple of the state and a cfg.Variable of coroutines.
Helper for _to_coroutine. Args: state: The current state. b: A cfg.Binding. bad_bindings: Bindings that are not coroutines. ret: A return variable that this helper will add to. top: Whether this is the top-level recursive call. ctx: The current context. Returns: The state.
Process the temporary classes created by six.with_metaclass. six.with_metaclass constructs an anonymous class holding a metaclass and a list of base classes; if we find instances in `bases`, store the first metaclass we find and remove all metaclasses from `bases`. Args: bases: The list of base classes for the class being constructed. ctx: The current context. Returns: A tuple of (metaclass, base classes)
Sequence[ str]
, ctx) -> Sequence[ Union[ abstract.InterpreterClass, abstract.InterpreterFunction]]
:
(source)
¶
Gets the class or function objects for a sequence of nested scope names. For example, if the code under analysis is: class Foo: def f(self): def g(): ... then when called with ['Foo', 'f', 'g'], this method returns [InterpreterClass(Foo), InterpreterFunction(f), InterpreterFunction(g)]. Arguments: state: The current state. names: A sequence of names for consecutive nested scopes in the module under analysis. Must start with a module-level name. ctx: The current context. Returns: The class or function object corresponding to each name in 'names'.
Check whether subcls_var overrides or newly defines the given attribute. Args: subcls: A potential subclass. supercls: A potential superclass. attr: An attribute name. Returns: True if subcls_var is a subclass of supercls_var and overrides or newly defines the attribute. False otherwise.