Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3.7 #271

Closed
myint opened this issue May 28, 2017 · 4 comments · Fixed by #273
Closed

Support Python 3.7 #271

myint opened this issue May 28, 2017 · 4 comments · Fixed by #273

Comments

@myint
Copy link
Member

myint commented May 28, 2017

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.

@myint
Copy link
Member Author

myint commented May 29, 2017

I got some responses from the Python bug tracker. They confirm my suspicion that there is no longer an easy way to get the line number of a docstring.

The doctest checking feature has been disabled by default since 5207ca6. I'm not sure if I've even used this feature before. My main interest was just to get the unit tests passing in Python 3.7.

I think @jayvdb has worked with the doctest parsing code the most recently out of all of us. And I think @mgedmin contributed the doctest checking feature in 5e962f0. What do you guys think would be the appropriate approach to this problem?

@mgedmin
Copy link
Contributor

mgedmin commented May 29, 2017

I'm fine with the simplifying assumption that a docstring starts on the next line after the function definition. Incorrect line numbers in warnings are better than a completely broken feature.

At some point somebody will be sufficiently annoyed that they'll contribute a fix to make the line numbers correct, even if they do so by inspecting the source file to find the first """ after the def.

myint added a commit that referenced this issue May 29, 2017
@myint
Copy link
Member Author

myint commented May 29, 2017

So here is the option we are discussing in code:

https://github.com/PyCQA/pyflakes/compare/python37

@mgedmin
Copy link
Contributor

mgedmin commented May 29, 2017

That looks acceptable to me.

myint added a commit that referenced this issue May 29, 2017
myint added a commit that referenced this issue May 29, 2017
@myint myint closed this as completed in #273 Jun 6, 2017
myint added a commit that referenced this issue Jun 6, 2017
* Ignore temporary files

* Support Python 3.7

This fixes #271.

* Re-enable nightly in Travis CI

This relates to #90.

* Undo 821a069
@hugovk hugovk mentioned this issue Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants