Various bits of reusable code related to ast.AST
node processing.
Class |
|
Generic AST node visitor. This class does not work like ast.NodeVisitor , it only visits statements directly within a body. Also, visitor methods can't return anything. |
Class |
|
Undocumented |
Class | op |
This class provides data and functions for mapping AST nodes to symbols and precedences. |
Class |
|
Add parent attribute to ast nodes instances. |
Class |
|
Wraps ast.Constant/ast.Str for `isinstance` checks and annotations. Ensures that the value is actually a string. Do not try to instanciate this class. |
Function | bind |
Binds the arguments of a function call to that function's signature. |
Function | extract |
Extract docstring information from an ast node that represents the docstring. |
Function | extract |
In older CPython versions, the AST only tells us the end line number and we must approximate the start line number. This approximation is correct if the docstring does not contain explicit newlines ('\n') or joined lines ('\' at end of line). |
Function | get |
Return the docstring node for the given class, function or module or None if no docstring can be found. |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | get |
Once nodes have the .parent attribute with {Parentage}, use this function to get a iterator on all parents of the given node up to the root module. |
Function | get |
Undocumented |
Function | infer |
Infer a literal expression's type. |
Function | is |
Returns whether or not the given ast.Compare is equal to __name__ == '__main__'. |
Function | is |
Does this AST node represent the literal constant None? |
Function | is |
Whether this annotation node refers to a typing alias. |
Function | is |
Detect if this expr is firstly composed by one of the specified annotation(s)' full name. |
Function | is |
Undocumented |
Function | is |
Undocumented |
Function | iter |
Undocumented |
Function | iterassign |
Utility function to iterate assignments targets. |
Function | node2dottedname |
Resove expression composed by ast.Attribute and ast.Name nodes to a list of names. |
Function | node2fullname |
Undocumented |
Function | unparse |
This function convert a node tree back into python sourcecode. |
Function | unstring |
Replace all strings in the given expression by parsed versions. |
Constant | SUBSCRIPTABLE |
Undocumented |
Constant | TYPING |
Undocumented |
Class | _ |
Implementation of unstring_annotation() . |
Class | _ |
Undocumented |
Function | _annotation |
Undocumented |
Function | _annotation |
Undocumented |
Function | _is |
Undocumented |
Type Alias | _ |
Undocumented |
Variable | _deprecated |
Undocumented |
Variable | _op |
Undocumented |
Variable | _precedence |
Undocumented |
Variable | _string |
True iff the 'lineno' attribute of an AST string node points to the last line in the string, rather than the first line. |
Variable | _symbol |
Undocumented |
Binds the arguments of a function call to that function's signature.
Raises | |
TypeError | If the arguments do not match the signature. |
Extract docstring information from an ast node that represents the docstring.
Returns | |
Tuple[ |
|
In older CPython versions, the AST only tells us the end line number and we must approximate the start line number. This approximation is correct if the docstring does not contain explicit newlines ('\n') or joined lines ('\' at end of line).
Leading blank lines are stripped by cleandoc(), so we must return the line number of the first non-blank line.
Return the docstring node for the given class, function or module or None if no docstring can be found.
Once nodes have the .parent attribute with {Parentage}, use this function to get a iterator on all parents of the given node up to the root module.
Infer a literal expression's type.
Parameters | |
expr:ast.expr | The expression's AST. |
Returns | |
Optional[ | A type annotation, or None if the expression has no obvious type. |
Optional[ ast.AST]
, annotations: Sequence[ str]
, ctx: model.Documentable
) -> bool
:
(source)
¶
Detect if this expr is firstly composed by one of the specified annotation(s)' full name.
Utility function to iterate assignments targets.
Useful for all the following AST assignments:
>>> var:int=2 >>> self.var = target = node.astext() >>> lol = ['extensions']
NOT Useful for the following AST assignments:
>>> x, y = [1,2]
Example:
>>> from pydoctor.astutils import iterassign >>> from ast import parse >>> node = parse('self.var = target = thing[0] = node.astext()').body[0] >>> list(iterassign(node))
This function convert a node tree back into python sourcecode.
Uses ast.unparse
or astor.to_source for python versions before 3.9.
ast.expr
, ctx: model.Documentable
, section: str
= 'annotation') -> ast.expr
:
(source)
¶
Replace all strings in the given expression by parsed versions.
Returns | |
ast.expr | The unstringed node. If parsing fails, an error is logged and the original node is returned. |
Undocumented
Value |
|