diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-22 16:51:34 +0100 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-22 16:51:34 +0100 |
commit | 5e014ff04380172362e4b69755e25c2aec787b1a (patch) | |
tree | 7245c741440d270530ddb945f1e93027ddfc8bec | |
parent | d853ab439edca2c29bd5a2cd5d26725a4beabdbd (diff) | |
download | pyflakes-5e014ff04380172362e4b69755e25c2aec787b1a.tar.gz |
Do not complain about _ in doctests; fixes lp:1178096
-rw-r--r-- | NEWS.txt | 1 | ||||
-rw-r--r-- | pyflakes/checker.py | 5 | ||||
-rw-r--r-- | pyflakes/test/test_doctests.py | 13 |
3 files changed, 19 insertions, 0 deletions
@@ -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 + ''') |