Skip to contentSkip to conversation

codegen: implement ast.NodeVisitor.visit_Constant

PATCH New Ross Burton 1 participant 1 message Oct 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 codegen: implement ast.NodeVisitor.visit_Constant

Since Python 3.8 visit_Num(), visit_Str() and so on are all deprecated and replaced with visit_Constant. We can't yet remove the deprecated functions until we require 3.8, but we can implement visit_Constant to silence the deprecation warnings.

---
 bitbake/lib/codegen.py | 6 ++++++
 1 file changed, 6 insertions(+)
bitbake/lib/codegen.py +6 -0
index 62a6748c47..6955a7ada5 100644
@@ -401,6 +401,12 @@ class SourceGenerator(NodeVisitor):
     def visit_Num(self, node):
         self.write(repr(node.n))
 
+    def visit_Constant(self, node):
+        # Python 3.8 deprecated visit_Num(), visit_Str(), visit_Bytes(),
+        # visit_NameConstant() and visit_Ellipsis(). They can be removed once we
+        # require 3.8+.
+        self.write(repr(node.value))
+
     def visit_Tuple(self, node):
         self.write('(')
         idx = -1
Signature · 1 line
2.25.1