From ebf5850cb9c885f793a39e1f7e4b1f95dbb18475 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 6 Jun 2017 08:55:05 +0200 Subject: [PATCH] Add normalizer support for E701-E704. --- parso/python/normalizer.py | 14 ++++++++++++++ test/normalizer_issue_files/E70.py | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/normalizer_issue_files/E70.py diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index abd3725..729ac1e 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -119,6 +119,20 @@ class PEP8Normalizer(Normalizer): self.add_issue(743, message % 'function', leaf) else: self.add_issuadd_issue(741, message % 'variables', leaf) + elif leaf.value == ':': + from parso.python.tree import Flow, Scope + if isinstance(leaf.parent, (Flow, Scope)) and leaf.parent.type != 'lambdef': + next_leaf = leaf.get_next_leaf() + if next_leaf.type != 'newline': + if leaf.parent.type == 'funcdef': + self.add_issue(704, 'Multiple statements on one line (def)', next_leaf) + else: + self.add_issue(701, 'Multiple statements on one line (colon)', next_leaf) + elif leaf.value == ';': + if leaf.get_next_leaf().type in ('newline', 'endmarker'): + self.add_issue(703, 'Statement ends with a semicolon', leaf) + else: + self.add_issue(702, 'Multiple statements on one line (semicolon)', leaf) for part in leaf._split_prefix(): part diff --git a/test/normalizer_issue_files/E70.py b/test/normalizer_issue_files/E70.py new file mode 100644 index 0000000..f91e0c5 --- /dev/null +++ b/test/normalizer_issue_files/E70.py @@ -0,0 +1,21 @@ +#: E701:6 +if a: a = False +#: E701:41 +if not header or header[:6] != 'bytes=': return +#: E702:9 +a = False; b = True +#: E702:16 E402 +import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe) +#: E703:12 E402 +import shlex; +#: E702:8 E703:22 +del a[:]; a.append(42); +#: E704:10 +def f(x): return 2 +#: E704:16 +async def f(x): return 2 +#: E704:10 +def f(x): return 2 * x +while all is round: + #: E704:10 + def f(x): return 2 * x