Skip to content

ExpressionAnalyzer

Handsdown API Index / Handsdown / AST Parser / Analyzers / ExpressionAnalyzer

Auto-generated documentation for handsdown.ast_parser.analyzers.expression_analyzer module.

ExpressionAnalyzer

Show source in expression_analyzer.py:13

Attributes

  • UNKNOWN - dummy value to replace unknown nodes and operators: '...'

  • BINOP_SYMBOLS: Dict[Type[ast.AST], str] - representation map for binary operators: {ast.Add: '+', ast.Sub: '-', ast.Mult: '', ast.Div: '/', ast.Mod: '%', ast.Pow: '*', ast.LShift: '<<', ast.RShift: '>>', ast.BitOr: '|', ast.BitXor: '^', ast.BitAnd: '&', ast.FloorDiv: '//'}

  • BOOLOP_SYMBOLS: Dict[Type[ast.AST], str] - representation map for boolean operators: {ast.And: 'and', ast.Or: 'or'}

  • CMPOP_SYMBOLS: Dict[Type[ast.AST], str] - representation map for comparison operators: {ast.Eq: '==', ast.NotEq: '!=', ast.Lt: '<', ast.LtE: '<=', ast.Gt: '>', ast.GtE: '>=', ast.Is: 'is', ast.IsNot: 'is not', ast.In: 'in', ast.NotIn: 'not in'}

  • UNARYOP_SYMBOLS: Dict[Type[ast.AST], str] - representation map for unary operators: {ast.Invert: '~', ast.Not: 'not', ast.UAdd: '+', ast.USub: '-'}

AST analyzer for ast.expr records.

Prepares parts for NodeRecord.render method.

Signature

class ExpressionAnalyzer(BaseAnalyzer):
    def __init__(self) -> None:
        ...

See also

ExpressionAnalyzer()._visit_iterable

Show source in expression_analyzer.py:181

Parse info from an iterable node and put it to parts.

Used for ast.Tuple, ast.Subscript, ast.List, ast.Set

Examples

[1, 2, 3]
{1, 2, 3}
(1, 2, 3)
Union[str, bool]

Arguments

  • node - AST node.

Signature

def _visit_iterable(self, node: ASTIterable) -> None:
    ...

See also

ExpressionAnalyzer().generic_visit

Show source in expression_analyzer.py:754

Parse info from an unknown ast.AST node and put ... to parts.

Logs warning with node class.

Arguments

  • node - AST node.

Signature

def generic_visit(self, node: ast.AST) -> None:
    ...

ExpressionAnalyzer().visit_Attribute

Show source in expression_analyzer.py:166

Parse info from ast.Attribute node and put it to parts.

Examples

my_object.attribute

Arguments

  • node - AST node.

Signature

def visit_Attribute(self, node: ast.Attribute) -> None:
    ...

ExpressionAnalyzer().visit_Await

Show source in expression_analyzer.py:709

Parse info from ast.Await node and put it to parts.

Examples

await result

Arguments

  • node - AST node.

Signature

def visit_Await(self, node: ast.Await) -> None:
    ...

ExpressionAnalyzer().visit_BinOp

Show source in expression_analyzer.py:367

Parse info from ast.BinOp node and put it to parts.

Examples

1 + 5
value + 1

Arguments

  • node - AST node.

Signature

def visit_BinOp(self, node: ast.BinOp) -> None:
    ...

ExpressionAnalyzer().visit_BoolOp

Show source in expression_analyzer.py:388

Parse info from ast.BoolOp node and put it to parts.

Examples

value or True
a and b

Arguments

  • node - AST node.

Signature

def visit_BoolOp(self, node: ast.BoolOp) -> None:
    ...

ExpressionAnalyzer().visit_Bytes

Show source in expression_analyzer.py:85

Parse info from ast.Bytes node and put it to parts.

Examples

b"my_string"

Arguments

  • node - AST node.

Signature

def visit_Bytes(self, node: ast.Bytes) -> None:
    ...

ExpressionAnalyzer().visit_Call

Show source in expression_analyzer.py:257

Parse info from ast.Call node and put it to parts.

Arguments

  • node - AST node.

Signature

def visit_Call(self, node: ast.Call) -> None:
    ...

ExpressionAnalyzer().visit_Compare

Show source in expression_analyzer.py:344

Parse info from ast.Compare node and put it to parts.

Examples

value < 5
1 < weekday < 7

Arguments

  • node - AST node.

Signature

def visit_Compare(self, node: ast.Compare) -> None:
    ...

ExpressionAnalyzer().visit_Dict

Show source in expression_analyzer.py:326

Parse info from ast.Dict node and put it to parts.

Arguments

  • node - AST node.

Signature

def visit_Dict(self, node: ast.Dict) -> None:
    ...

ExpressionAnalyzer().visit_DictComp

Show source in expression_analyzer.py:618

Parse info from ast.DictComp node and put it to parts.

Examples

{k: 1 for k in range(3)}

Arguments

  • node - AST node.

Signature

def visit_DictComp(self, node: ast.DictComp) -> None:
    ...

ExpressionAnalyzer().visit_Ellipsis

Show source in expression_analyzer.py:525

Parse info from ast.Ellipsis node and put it to parts.

Examples

...

Arguments

  • node - AST node.

Signature

def visit_Ellipsis(self, node: ast.ASTEllipsis) -> None:
    ...

ExpressionAnalyzer().visit_FormattedValue

Show source in expression_analyzer.py:584

Parse info from ast.FormattedValue node and put it to parts.

Examples

f"{formatted_value}"

Arguments

  • node - AST node.

Signature

def visit_FormattedValue(self, node: ast.FormattedValue) -> None:
    ...

ExpressionAnalyzer().visit_GeneratorExp

Show source in expression_analyzer.py:674

Parse info from ast.GeneratorExp node and put it to parts.

Examples

(k + 1 for k in range(3))

Arguments

  • node - AST node.

Signature

def visit_GeneratorExp(self, node: ast.GeneratorExp) -> None:
    ...

ExpressionAnalyzer().visit_IfExp

Show source in expression_analyzer.py:692

Parse info from ast.IfExp node and put it to parts.

Examples

5 if my_value else 6

Arguments

  • node - AST node.

Signature

def visit_IfExp(self, node: ast.IfExp) -> None:
    ...

ExpressionAnalyzer().visit_Index

Show source in expression_analyzer.py:508

Parse info from ast.Index node and put it to parts.

Examples

Union[str, bool]
Union[str]

Arguments

  • node - AST node.

Signature

def visit_Index(self, node: ast.Index) -> None:
    ...

ExpressionAnalyzer().visit_JoinedStr

Show source in expression_analyzer.py:562

Parse info from ast.JoinedStr node and put it to parts.

Examples

f'str: {my_string}'

Arguments

  • node - AST node.

Signature

def visit_JoinedStr(self, node: ast.JoinedStr) -> None:
    ...

ExpressionAnalyzer().visit_Lambda

Show source in expression_analyzer.py:432

Parse info from ast.Lambda node and put it to parts.

Examples

lambda x: x + 5

Arguments

  • node - AST node.

Signature

def visit_Lambda(self, node: ast.Lambda) -> None:
    ...

ExpressionAnalyzer().visit_List

Show source in expression_analyzer.py:212

Parse info from ast.List node and put it to parts.

Examples

[1, 2, 3]

Arguments

  • node - AST node.

Signature

def visit_List(self, node: ast.List) -> None:
    ...

ExpressionAnalyzer().visit_ListComp

Show source in expression_analyzer.py:638

Parse info from ast.ListComp node and put it to parts.

Examples

[k + 1 for k in range(3)]

Arguments

  • node - AST node.

Signature

def visit_ListComp(self, node: ast.ListComp) -> None:
    ...

ExpressionAnalyzer().visit_Name

Show source in expression_analyzer.py:114

Parse info from ast.Name node and put it to parts.

Examples

my_value

Arguments

  • node - AST node.

Signature

def visit_Name(self, node: ast.Name) -> None:
    ...

ExpressionAnalyzer().visit_NameConstant

Show source in expression_analyzer.py:128

Parse info from ast.NameConstant node and put it to parts.

Examples

None
True

Arguments

  • node - AST node.

Signature

def visit_NameConstant(self, node: ast.NameConstant) -> None:
    ...

ExpressionAnalyzer().visit_Num

Show source in expression_analyzer.py:99

Parse info from ast.Num node and put it to parts.

Examples

123
123.456

Arguments

  • node - AST node.

Signature

def visit_Num(self, node: ast.Num) -> None:
    ...

ExpressionAnalyzer().visit_Set

Show source in expression_analyzer.py:227

Parse info from ast.Set node and put it to parts.

Examples

{1, 2, 3}

Arguments

  • node - AST node.

Signature

def visit_Set(self, node: ast.Set) -> None:
    ...

ExpressionAnalyzer().visit_SetComp

Show source in expression_analyzer.py:656

Parse info from ast.SetComp node and put it to parts.

Examples

{k + 1 for k in range(3)}

Arguments

  • node - AST node.

Signature

def visit_SetComp(self, node: ast.SetComp) -> None:
    ...

ExpressionAnalyzer().visit_Slice

Show source in expression_analyzer.py:538

Parse info from ast.Slice node and put it to parts.

Examples

[1:]
[:2]
[1:2]
[1:2:-1]
[::-1]

Arguments

  • node - AST node.

Signature

def visit_Slice(self, node: ast.Slice) -> None:
    ...

ExpressionAnalyzer().visit_Starred

Show source in expression_analyzer.py:291

Parse info from ast.Starred node and put it to parts.

Examples

*arg

Arguments

  • node - AST node.

Signature

def visit_Starred(self, node: ast.Starred) -> None:
    ...

ExpressionAnalyzer().visit_Str

Show source in expression_analyzer.py:69

Parse info from ast.Str node and put it to parts.

Examples

"my_string"

Arguments

  • node - AST node.

Signature

def visit_Str(self, node: ast.Str) -> None:
    ...

ExpressionAnalyzer().visit_Subscript

Show source in expression_analyzer.py:142

Parse info from ast.Subscript node and put it to parts.

Type annotations are also matched by this method.

Examples

Union[Name, bool]
List[1:4]

Arguments

  • node - AST node.

Signature

def visit_Subscript(self, node: ast.Subscript) -> None:
    ...

ExpressionAnalyzer().visit_Tuple

Show source in expression_analyzer.py:242

Parse info from ast.Tuple node and put it to parts.

Examples

(1, 2, 3)

Arguments

  • node - AST node.

Signature

def visit_Tuple(self, node: ast.Tuple) -> None:
    ...

ExpressionAnalyzer().visit_UnaryOp

Show source in expression_analyzer.py:410

Parse info from ast.UnaryOp node and put it to parts.

Examples

+5
-12
~1
not True

Arguments

  • node - AST node.

Signature

def visit_UnaryOp(self, node: ast.UnaryOp) -> None:
    ...

ExpressionAnalyzer().visit_Yield

Show source in expression_analyzer.py:723

Parse info from ast.Yield node and put it to parts.

Examples

yield
yield value

Arguments

  • node - AST node.

Signature

def visit_Yield(self, node: ast.Yield) -> None:
    ...

ExpressionAnalyzer().visit_YieldFrom

Show source in expression_analyzer.py:740

Parse info from ast.YieldFrom node and put it to parts.

Examples

yield from my_generator

Arguments

  • node - AST node.

Signature

def visit_YieldFrom(self, node: ast.YieldFrom) -> None:
    ...

ExpressionAnalyzer().visit_arg

Show source in expression_analyzer.py:491

Parse info from ast.arg node and put it to parts.

Examples

def my_func(arg)
def my_func(arg: str)

Arguments

  • node - AST node.

Signature

def visit_arg(self, node: ast.arg) -> None:
    ...

ExpressionAnalyzer().visit_arguments

Show source in expression_analyzer.py:448

Parse info from ast.arguments node and put it to parts.

Examples

def my_func(arg, *args, **kwargs)

Arguments

  • node - AST node.

Signature

def visit_arguments(self, node: ast.arguments) -> None:
    ...

ExpressionAnalyzer().visit_comprehension

Show source in expression_analyzer.py:599

Parse info from ast.comprehension node and put it to parts.

Examples

for k in range(3) if k > 0 if True

Arguments

  • node - AST node.

Signature

def visit_comprehension(self, node: ast.comprehension) -> None:
    ...

ExpressionAnalyzer().visit_keyword

Show source in expression_analyzer.py:305

Parse info from ast.keyword node and put it to parts.

Examples

my_func(**{"kwarg": "value"})
my_func(kwarg="value")

Arguments

  • node - AST node.

Signature

def visit_keyword(self, node: ast.keyword) -> None:
    ...