[issue36917] ast.NodeVisitor no longer calls visit_Str

Serhiy Storchaka report at bugs.python.org
Mon Aug 26 08:14:21 EDT 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Thank you for your report and discussion Anthony.

Added the default implementation of visit_Constant which calls corresponding visitor for old constant nodes. It emits a deprecation warning (PendingDeprecationWarning in 3.8 and DeprecationWarning in 3.9) as a reminder that you finally will need to implement your own visit_Constant. You can temporary ignore them.

Note that the implementation in the stdlib is not future proof (and it should not, because visit_Constant will likely be removed at the same time or before removing classes Num and Str and removing properties "n" and "s" from Constant). In long term solution you should write something like:

class V(ast.NodeVisitor):
    def _visit_string(self, node, value):
        ...

    def visit_Str(self, node):
        return self._visit_string(node, node.s)

    def visit_Constant(self, node):
        if isinstance(node.value, str):
            return self._visit_string(node, node.value)
        ...

Otherwise you can get other deprecation warnings or errors in future releases.

----------
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36917>
_______________________________________


More information about the Python-bugs-list mailing list