summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Watters <kevinwatters@gmail.com>2014-02-26 18:58:55 -0800
committerKevin Watters <kevinwatters@gmail.com>2014-02-26 18:58:55 -0800
commit8c6256cf81fda0f8e704acd3d0d275386285cd4c (patch)
treef99842fcdf93f5cc3086b5dbd054a8cf637b04b0
parent1fc3faf1320c7c903c63f5b839e986c98a13a6a3 (diff)
parent5207ca66fe2b61d88d28885ab58d18414981c60a (diff)
downloadpyflakes-8c6256cf81fda0f8e704acd3d0d275386285cd4c.tar.gz
Merge pull request #25 from exarkun/enable-doctests-with-flag
Turn off doctest checking by default.
-rw-r--r--NEWS.txt5
-rw-r--r--pyflakes/checker.py5
-rw-r--r--pyflakes/test/harness.py4
-rw-r--r--pyflakes/test/test_doctests.py2
4 files changed, 13 insertions, 3 deletions
diff --git a/NEWS.txt b/NEWS.txt
index 56c251c..ec6bffe 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -3,6 +3,11 @@ UNRELEASED:
- Fix caret position on SyntaxError.
- Fix crash on Python 2.x with some doctest SyntaxError.
- Add tox.ini.
+ - The `PYFLAKES_NODOCTEST` environment variable has been replaced with the
+ `PYFLAKES_DOCTEST` environment variable (with the opposite meaning).
+ Doctest checking is now disabled by default; set the environment variable
+ to enable it.
+
0.7.3 (2013-07-02):
- Do not report undefined name for generator expression and dict or
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 04491f9..1cab12e 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -231,7 +231,6 @@ class Checker(object):
nodeDepth = 0
offset = None
traceTree = False
- withDoctest = ('PYFLAKES_NODOCTEST' not in os.environ)
builtIns = set(builtin_vars).union(_MAGIC_GLOBALS)
_customBuiltIns = os.environ.get('PYFLAKES_BUILTINS')
@@ -239,7 +238,8 @@ class Checker(object):
builtIns.update(_customBuiltIns.split(','))
del _customBuiltIns
- def __init__(self, tree, filename='(none)', builtins=None):
+ def __init__(self, tree, filename='(none)', builtins=None,
+ withDoctest='PYFLAKES_DOCTEST' in os.environ):
self._nodeHandlers = {}
self._deferredFunctions = []
self._deferredAssignments = []
@@ -248,6 +248,7 @@ class Checker(object):
self.filename = filename
if builtins:
self.builtIns = self.builtIns.union(builtins)
+ self.withDoctest = withDoctest
self.scopeStack = [ModuleScope()]
self.exceptHandlers = [()]
self.futuresAllowed = True
diff --git a/pyflakes/test/harness.py b/pyflakes/test/harness.py
index 9f337e5..a781237 100644
--- a/pyflakes/test/harness.py
+++ b/pyflakes/test/harness.py
@@ -18,9 +18,11 @@ PyCF_ONLY_AST = 1024
class TestCase(unittest.TestCase):
+ withDoctest = False
+
def flakes(self, input, *expectedOutputs, **kw):
tree = compile(textwrap.dedent(input), "<test>", "exec", PyCF_ONLY_AST)
- w = checker.Checker(tree, **kw)
+ w = checker.Checker(tree, withDoctest=self.withDoctest, **kw)
outputs = [type(o) for o in w.messages]
expectedOutputs = list(expectedOutputs)
outputs.sort(key=lambda t: t.__name__)
diff --git a/pyflakes/test/test_doctests.py b/pyflakes/test/test_doctests.py
index d7df779..8ff9620 100644
--- a/pyflakes/test/test_doctests.py
+++ b/pyflakes/test/test_doctests.py
@@ -9,6 +9,8 @@ from pyflakes.test.harness import skip
class Test(TestOther, TestImports, TestUndefinedNames):
+ withDoctest = True
+
def doctestify(self, input):
lines = []
for line in textwrap.dedent(input).splitlines():