summaryrefslogtreecommitdiff
path: root/pyflakes/checker.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyflakes/checker.py')
-rw-r--r--pyflakes/checker.py59
1 files changed, 16 insertions, 43 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index a79de56..13d2452 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -18,7 +18,6 @@ import warnings
from pyflakes import messages
-PY38_PLUS = sys.version_info >= (3, 8)
PYPY = hasattr(sys, 'pypy_version_info')
builtin_vars = dir(builtins)
@@ -35,15 +34,12 @@ def getAlternatives(n):
FOR_TYPES = (ast.For, ast.AsyncFor)
-if PY38_PLUS:
- def _is_singleton(node): # type: (ast.AST) -> bool
- return (
- isinstance(node, ast.Constant) and
- isinstance(node.value, (bool, type(Ellipsis), type(None)))
- )
-else:
- def _is_singleton(node): # type: (ast.AST) -> bool
- return isinstance(node, (ast.NameConstant, ast.Ellipsis))
+
+def _is_singleton(node): # type: (ast.AST) -> bool
+ return (
+ isinstance(node, ast.Constant) and
+ isinstance(node.value, (bool, type(Ellipsis), type(None)))
+ )
def _is_tuple_constant(node): # type: (ast.AST) -> bool
@@ -53,16 +49,8 @@ def _is_tuple_constant(node): # type: (ast.AST) -> bool
)
-if PY38_PLUS:
- def _is_constant(node):
- return isinstance(node, ast.Constant) or _is_tuple_constant(node)
-else:
- def _is_constant(node):
- return (
- isinstance(node, (ast.Str, ast.Num, ast.Bytes)) or
- _is_singleton(node) or
- _is_tuple_constant(node)
- )
+def _is_constant(node):
+ return isinstance(node, ast.Constant) or _is_tuple_constant(node)
def _is_const_non_singleton(node): # type: (ast.AST) -> bool
@@ -1176,7 +1164,7 @@ class Checker:
)
):
binding = ExportBinding(name, node._pyflakes_parent, self.scope)
- elif PY38_PLUS and isinstance(parent_stmt, ast.NamedExpr):
+ elif isinstance(parent_stmt, ast.NamedExpr):
binding = NamedExprAssignment(name, node)
else:
binding = Assignment(name, node)
@@ -1252,13 +1240,7 @@ class Checker:
if not isinstance(node, ast.Str):
return (None, None)
- if PYPY or PY38_PLUS:
- doctest_lineno = node.lineno - 1
- else:
- # Computed incorrectly if the docstring has backslash
- doctest_lineno = node.lineno - node.s.count('\n') - 1
-
- return (node.s, doctest_lineno)
+ return (node.s, node.lineno - 1)
def handleNode(self, node, parent):
if node is None:
@@ -1729,12 +1711,9 @@ class Checker:
else:
self.deferFunction(fn)
- if PY38_PLUS:
- def CONSTANT(self, node):
- if isinstance(node.value, str):
- return self.STR(node)
- else:
- NUM = BYTES = ELLIPSIS = CONSTANT = ignore
+ def CONSTANT(self, node):
+ if isinstance(node.value, str):
+ return self.STR(node)
# "slice" type nodes
SLICE = EXTSLICE = INDEX = handleChildren
@@ -1900,11 +1879,6 @@ class Checker:
return
if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
break
- # Handle Try/TryFinally difference in Python < and >= 3.3
- if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
- if n_child in n.finalbody and not PY38_PLUS:
- self.report(messages.ContinueInFinally, node)
- return
if isinstance(node, ast.Continue):
self.report(messages.ContinueOutsideLoop, node)
else: # ast.Break
@@ -1952,10 +1926,9 @@ class Checker:
args = []
annotations = []
- if PY38_PLUS:
- for arg in node.args.posonlyargs:
- args.append(arg.arg)
- annotations.append(arg.annotation)
+ for arg in node.args.posonlyargs:
+ args.append(arg.arg)
+ annotations.append(arg.annotation)
for arg in node.args.args + node.args.kwonlyargs:
args.append(arg.arg)
annotations.append(arg.annotation)