Reputation: 2822
I am trying to convert an older library that maps dependencies called snakefood over to Python 3. I have 2 parts I can't figure out what to substitute as I can't find documentation on what either function does - from compiler.ast import Discard, Const
I can't seem to find an equivalent in Python 3 in the ast
library. Here are the function calls from Python 2, see both here being used in isinstance()
calls:
def default(self, node):
pragma = None
if self.recent:
if isinstance(node, Discard):
children = node.getChildren()
if len(children) == 1 and isinstance(children[0], Const):
const_node = children[0]
pragma = const_node.value
self.accept_imports(pragma)
Apologies for not understanding this stuff, I just learned about AST calls trying to use this library. Much appreciated.
Upvotes: 0
Views: 776
Reputation: 69914
Discard
(took me a while to figure out what it does) is now Expr
(though this includes more things than previously)
I got this hint from the source of compiler/codegen.py:
def visitDiscard(self, node):
# XXX Discard means it's an expression. Perhaps this is a bad
# name.
Const
has been replaced with several different types which represent various constants, notably Num
, Str
, JoinedStr
, and a few others. The documentation for all the ast types can be found here.
Upvotes: 1