diff --git a/NEWS.txt b/NEWS.txt index 56c251c1..ec6bffe2 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 04491f9f..1cab12e0 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 @@ def __init__(self, tree, filename='(none)', builtins=None): 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 9f337e58..a781237d 100644 --- a/pyflakes/test/harness.py +++ b/pyflakes/test/harness.py @@ -18,9 +18,11 @@ class TestCase(unittest.TestCase): + withDoctest = False + def flakes(self, input, *expectedOutputs, **kw): tree = compile(textwrap.dedent(input), "", "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 d7df7792..8ff96203 100644 --- a/pyflakes/test/test_doctests.py +++ b/pyflakes/test/test_doctests.py @@ -9,6 +9,8 @@ class Test(TestOther, TestImports, TestUndefinedNames): + withDoctest = True + def doctestify(self, input): lines = [] for line in textwrap.dedent(input).splitlines():