From 3216c7b362bfc6e86a9b342c0e364750a972a65e Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 5 Dec 2018 06:06:49 -0800 Subject: [PATCH] Remove workarounds for older, unsupported Pythons --- docs/source/internal/checker.rst | 2 -- src/flake8/checker.py | 14 -------------- src/flake8/processor.py | 17 ----------------- src/flake8/utils.py | 11 +++++------ 4 files changed, 5 insertions(+), 39 deletions(-) diff --git a/docs/source/internal/checker.rst b/docs/source/internal/checker.rst index 19bcf7d..d11117c 100644 --- a/docs/source/internal/checker.rst +++ b/docs/source/internal/checker.rst @@ -61,8 +61,6 @@ Utility Functions .. autofunction:: flake8.processor.mutate_string -.. autofunction:: flake8.processor.token_is_comment - .. autofunction:: flake8.processor.token_is_newline .. Substitutions diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 3b97414..8b1655b 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -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: diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 18f9f1d..692d9d4 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -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 diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 68627af..e5eef45 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -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(), + )