Skip to content

Support Python 3.7 #271

@myint

Description

@myint

I'm moving #90 (comment) here since we have GitHub issue support now.

It looks like the CPython 3.7 failure is related to a change in the AST. The docstring is no longer in node.body.

python/cpython#46

We can mostly replace our getDocstring(node.body[0]) call with node.docstring. But I'm not sure how to get the line number of the docstring anymore. node.lineno is close, but not quite the line number of the docstring.

(docstring, node_lineno) = self.getDocstring(node.body[0])

diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 382574e..2c19533 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -870,7 +870,11 @@ class Checker(object):

     def handleDoctests(self, node):
         try:
-            (docstring, node_lineno) = self.getDocstring(node.body[0])
+            if hasattr(node, 'docstring'):
+                docstring = node.docstring
+                node_lineno = ???  # TODO
+            else:
+                (docstring, node_lineno) = self.getDocstring(node.body[0])
             examples = docstring and self._getDoctestExamples(docstring)
         except (ValueError, IndexError):
             # e.g. line 6 of the docstring for <string> has inconsistent

I've reported this to the CPython issue tracker.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions