summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-03-22 16:51:34 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-03-22 16:51:34 +0100
commit5e014ff04380172362e4b69755e25c2aec787b1a (patch)
tree7245c741440d270530ddb945f1e93027ddfc8bec
parentd853ab439edca2c29bd5a2cd5d26725a4beabdbd (diff)
downloadpyflakes-5e014ff04380172362e4b69755e25c2aec787b1a.tar.gz
Do not complain about _ in doctests; fixes lp:1178096
-rw-r--r--NEWS.txt1
-rw-r--r--pyflakes/checker.py5
-rw-r--r--pyflakes/test/test_doctests.py13
3 files changed, 19 insertions, 0 deletions
diff --git a/NEWS.txt b/NEWS.txt
index f575057..9d26c84 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -9,6 +9,7 @@ UNRELEASED:
to enable it.
- Correctly parse incremental `__all__ += [...]`
- Catch return with arguments inside a generator (Python <= 3.2)
+ - Do not complain about `_` in doctests
0.7.3 (2013-07-02):
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 9b15511..57bcf61 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -584,7 +584,12 @@ class Checker(object):
else:
self.offset = (node_offset[0] + node_lineno + example.lineno,
node_offset[1] + example.indent + 4)
+ underscore_in_builtins = '_' in self.builtIns
+ if not underscore_in_builtins:
+ self.builtIns.add('_')
self.handleChildren(tree)
+ if not underscore_in_builtins:
+ self.builtIns.remove('_')
self.offset = node_offset
self.popScope()
diff --git a/pyflakes/test/test_doctests.py b/pyflakes/test/test_doctests.py
index 8ff9620..8c76815 100644
--- a/pyflakes/test/test_doctests.py
+++ b/pyflakes/test/test_doctests.py
@@ -228,3 +228,16 @@ class Test(TestOther, TestImports, TestUndefinedNames):
self.assertEqual(exc.lineno, 4)
exc = exceptions[1]
self.assertEqual(exc.lineno, 6)
+
+ def test_singleUnderscoreInDoctest(self):
+ super(Test, self).flakes('''
+ def func():
+ """A docstring
+
+ >>> func()
+ 1
+ >>> _
+ 1
+ """
+ return 1
+ ''')