Checking type determination with astroid for comparison operators
tree = astroid.parse('a + b') … print(tree.repr_tree()) …
python3
import astroid tree = astroid.parse('x == y') print(tree.repr_tree()) …
tree = astroid.parse('1 in (2, 3)') print(tree.repr_tree()) …
Hello,
The following information is provided by a documentation.
https://pylint.pycqa.org/projects/astroid/en/latest/inference.html#crash-cou...
“…
astroid offers a relatively similar API to the builtin ast module, that is, you can do astroid.parse(string) to get an AST out of the given string:
body=[Expr(value=BinOp(
op='+',
left=Name(name='a'),
right=Name(name='b')))])
The repr_tree() is super useful to inspect how a tree actually looks.
…”
Another information is provided by a related documentation.
https://docs.python.org/3/library/ast.html
“…
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
…”
I guess that the identifier at the beginning of such a line from
the abstract grammar should be interpreted as a comparison operator.
Additional command examples:
body=[Expr(value=Compare(
left=Name(name='x'),
ops=[['==', Name(name='y')]]))])
body=[Expr(value=Compare(
left=Const(value=1),
ops=[['in', Tuple(
ctx=
participants (1)
-
Markus Elfring