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 |
Get the docstring for a ast.Assign or ast.AnnAssign node. |
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 |
Tell in wich block the given node lives in. |
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 | unstring |
Replace all strings in the given expression by parsed versions. |
Function | upgrade |
Transform the annotation to use python 3.10+ syntax. |
Constant | DEPRECATED |
Undocumented |
Constant | SUBSCRIPTABLE |
Undocumented |
Constant | TYPING |
Undocumented |
Class | _ |
Implementation of unstring_annotation() . |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Function | _annotation |
Undocumented |
Function | _annotation |
Undocumented |
Function | _is |
Undocumented |
Type Alias | _ |
Undocumented |
Variable | _deprecated |
Undocumented |
Variable | _op |
Undocumented |
Variable | _precedence |
Undocumented |
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.
Get the docstring for a ast.Assign
or ast.AnnAssign
node.
This helper function relies on the non-standard .parent attribute on AST nodes to navigate upward in the tree and determine this node direct siblings.
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 | |
ast.expr | None | A type annotation, or None if the expression has no obvious type. |
ast.AST | None
, 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))
ast.AST | None
, ctx: model.Documentable | None
= None, *, expandName: Callable[ [ str], str] | None
= None) -> str | None
:
(source)
¶
Undocumented
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. |
ast.expr
, ctx: model.Documentable
, section: str
= 'annotation') -> ast.expr
:
(source)
¶
Transform the annotation to use python 3.10+ syntax.
Undocumented
Value |
|
Undocumented
Value |
|