From 5770b171d5e22455f230e983577307124655e2a7 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Sun, 30 Mar 2014 23:31:19 +0200 Subject: [PATCH] Add option 'doctests' to run Pyflakes checks on doctests too; issue #138 --- CHANGES.rst | 1 + flake8/_pyflakes.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 304b342..2668850 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ CHANGES 2.1.1 - unreleased ------------------ +- New option ``doctests`` to run Pyflakes checks on doctests too - Fix Git and Mercurial hooks, issues #88 and #133 - Fix crashes with Python 3.4 by upgrading dependencies - Fix traceback when running tests with Python 2.6 diff --git a/flake8/_pyflakes.py b/flake8/_pyflakes.py index cf80612..fff4fbf 100644 --- a/flake8/_pyflakes.py +++ b/flake8/_pyflakes.py @@ -38,16 +38,22 @@ class FlakesChecker(pyflakes.checker.Checker): name = 'pyflakes' version = pyflakes.__version__ + def __init__(self, tree, filename): + super(FlakesChecker, self).__init__(tree, filename, withDoctest=self.withDoctest) + @classmethod def add_options(cls, parser): parser.add_option('--builtins', help="define more built-ins, comma separated") - parser.config_options.append('builtins') + parser.add_option('--doctests', default=False, action='store_true', + help="check syntax of the doctests") + parser.config_options.extend(['builtins', 'doctests']) @classmethod def parse_options(cls, options): if options.builtins: cls.builtIns = cls.builtIns.union(options.builtins.split(',')) + cls.withDoctest = options.doctests def run(self): for m in self.messages: