Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ast
import collections
import contextlib
import doctest
import functools
import os
import re
Expand Down Expand Up @@ -40,6 +39,12 @@ def _custom_builtins() -> frozenset[str]:
parse_format_string = string.Formatter().parse


@functools.cache
def _doctest_parser():
import doctest
return doctest.DocTestParser().get_examples


def getAlternatives(n):
if isinstance(n, ast.If):
return [n.body]
Expand Down Expand Up @@ -1251,12 +1256,10 @@ def handleNode(self, node, parent):
finally:
self.nodeDepth -= 1

_getDoctestExamples = doctest.DocTestParser().get_examples

def handleDoctests(self, node):
try:
(docstring, node_lineno) = self.getDocstring(node.body[0])
examples = docstring and self._getDoctestExamples(docstring)
examples = docstring and _doctest_parser()(docstring)
except (ValueError, IndexError):
# e.g. line 6 of the docstring for <string> has inconsistent
# leading whitespace: ...
Expand Down
Loading