mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-02 19:56:52 +00:00
Merge branch 'old-py' into 'master'
Remove workarounds for older, unsupported Pythons See merge request pycqa/flake8!271
This commit is contained in:
commit
9a9237a338
4 changed files with 5 additions and 39 deletions
|
|
@ -61,8 +61,6 @@ Utility Functions
|
|||
|
||||
.. autofunction:: flake8.processor.mutate_string
|
||||
|
||||
.. autofunction:: flake8.processor.token_is_comment
|
||||
|
||||
.. autofunction:: flake8.processor.token_is_newline
|
||||
|
||||
.. Substitutions
|
||||
|
|
|
|||
|
|
@ -577,11 +577,6 @@ class FileChecker(object):
|
|||
elif parens == 0:
|
||||
if processor.token_is_newline(token):
|
||||
self.handle_newline(token_type)
|
||||
elif (
|
||||
processor.token_is_comment(token)
|
||||
and len(file_processor.tokens) == 1
|
||||
):
|
||||
self.handle_comment(token, text)
|
||||
|
||||
if file_processor.tokens:
|
||||
# If any tokens are left over, process them
|
||||
|
|
@ -606,15 +601,6 @@ class FileChecker(object):
|
|||
self.statistics["logical lines"] = logical_lines
|
||||
return self.filename, self.results, self.statistics
|
||||
|
||||
def handle_comment(self, token, token_text):
|
||||
"""Handle the logic when encountering a comment token."""
|
||||
# The comment also ends a physical line
|
||||
token = list(token)
|
||||
token[1] = token_text.rstrip("\r\n")
|
||||
token[3] = (token[2][0], token[2][1] + len(token[1]))
|
||||
self.processor.tokens = [tuple(token)]
|
||||
self.run_logical_checks()
|
||||
|
||||
def handle_newline(self, token_type):
|
||||
"""Handle the logic when encountering a newline token."""
|
||||
if token_type == tokenize.NEWLINE:
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ from flake8 import utils
|
|||
LOG = logging.getLogger(__name__)
|
||||
PyCF_ONLY_AST = 1024
|
||||
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
|
||||
# Work around Python < 2.6 behaviour, which does not generate NL after
|
||||
# a comment which is on a line by itself.
|
||||
COMMENT_WITH_NL = tokenize.generate_tokens(["#\n"].pop).send(None)[1] == "#\n"
|
||||
|
||||
SKIP_TOKENS = frozenset(
|
||||
[tokenize.NL, tokenize.NEWLINE, tokenize.INDENT, tokenize.DEDENT]
|
||||
|
|
@ -373,15 +370,6 @@ def is_eol_token(token):
|
|||
return token[0] in NEWLINE or token[4][token[3][1] :].lstrip() == "\\\n"
|
||||
|
||||
|
||||
if COMMENT_WITH_NL: # If on Python 2.6
|
||||
|
||||
def is_eol_token(token, _is_eol_token=is_eol_token):
|
||||
"""Check if the token is an end-of-line token."""
|
||||
return _is_eol_token(token) or (
|
||||
token[0] == tokenize.COMMENT and token[1] == token[4]
|
||||
)
|
||||
|
||||
|
||||
def is_multiline_string(token):
|
||||
"""Check if this is a multiline string."""
|
||||
return token[0] == tokenize.STRING and "\n" in token[1]
|
||||
|
|
@ -392,11 +380,6 @@ def token_is_newline(token):
|
|||
return token[0] in NEWLINE
|
||||
|
||||
|
||||
def token_is_comment(token):
|
||||
"""Check if the token type is a comment."""
|
||||
return COMMENT_WITH_NL and token[0] == tokenize.COMMENT
|
||||
|
||||
|
||||
def count_parentheses(current_parentheses_count, token_text):
|
||||
"""Count the number of parentheses."""
|
||||
current_parentheses_count = current_parentheses_count or 0
|
||||
|
|
|
|||
|
|
@ -376,9 +376,8 @@ def get_python_version():
|
|||
:rtype:
|
||||
str
|
||||
"""
|
||||
# The implementation isn't all that important.
|
||||
try:
|
||||
impl = platform.python_implementation() + " "
|
||||
except AttributeError: # Python 2.5
|
||||
impl = ""
|
||||
return "%s%s on %s" % (impl, platform.python_version(), platform.system())
|
||||
return "%s %s on %s" % (
|
||||
platform.python_implementation(),
|
||||
platform.python_version(),
|
||||
platform.system(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue