From 0c62569c4f75ffcbbe21561bd21c52b6e3021a12 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 14 Nov 2021 08:36:02 -0800 Subject: [PATCH] remove dead code detected using https://github.com/asottile/dead --- docs/source/internal/utils.rst | 5 ----- src/flake8/defaults.py | 2 -- src/flake8/options/manager.py | 28 ---------------------------- src/flake8/processor.py | 1 - src/flake8/utils.py | 11 ----------- tests/unit/test_option.py | 8 -------- tests/unit/test_utils.py | 9 --------- 7 files changed, 64 deletions(-) diff --git a/docs/source/internal/utils.rst b/docs/source/internal/utils.rst index e104d62..387ec82 100644 --- a/docs/source/internal/utils.rst +++ b/docs/source/internal/utils.rst @@ -54,11 +54,6 @@ normalized path. This function retrieves and caches the value provided on ``sys.stdin``. This allows plugins to use this to retrieve ``stdin`` if necessary. -.. autofunction:: flake8.utils.is_windows - -This provides a convenient and explicitly named function that checks if we are -currently running on a Windows (or ``nt``) operating system. - .. autofunction:: flake8.utils.is_using_stdin Another helpful function that is named only to be explicit given it is a very diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py index da0205e..a1c04fc 100644 --- a/src/flake8/defaults.py +++ b/src/flake8/defaults.py @@ -18,8 +18,6 @@ SELECT = ("E", "F", "W", "C90") MAX_LINE_LENGTH = 79 INDENT_SIZE = 4 -TRUTHY_VALUES = {"true", "1", "t"} - # Other constants WHITESPACE = frozenset(" \t") diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index 28cee4d..50bdf58 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -17,14 +17,10 @@ from typing import Sequence from typing import Set from typing import Tuple from typing import Type -from typing import TYPE_CHECKING from typing import Union from flake8 import utils -if TYPE_CHECKING: - from typing import NoReturn - LOG = logging.getLogger(__name__) # represent a singleton of "not passed arguments". @@ -310,34 +306,10 @@ class Option: return value - def normalize_from_setuptools( - self, value: str - ) -> Union[int, float, complex, bool, str]: - """Normalize the value received from setuptools.""" - value = self.normalize(value) - if self.type is int or self.action == "count": - return int(value) - elif self.type is float: - return float(value) - elif self.type is complex: - return complex(value) - if self.action in ("store_true", "store_false"): - value = str(value).upper() - if value in ("1", "T", "TRUE", "ON"): - return True - if value in ("0", "F", "FALSE", "OFF"): - return False - return value - def to_argparse(self) -> Tuple[List[str], Dict[str, Any]]: """Convert a Flake8 Option to argparse ``add_argument`` arguments.""" return self.option_args, self.filtered_option_kwargs - @property - def to_optparse(self) -> "NoReturn": - """No longer functional.""" - raise AttributeError("to_optparse: flake8 now uses argparse") - PluginVersion = collections.namedtuple( "PluginVersion", ["name", "version", "local"] diff --git a/src/flake8/processor.py b/src/flake8/processor.py index f632388..2649c9d 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -16,7 +16,6 @@ from flake8 import defaults from flake8 import utils LOG = logging.getLogger(__name__) -PyCF_ONLY_AST = 1024 NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) SKIP_TOKENS = frozenset( diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 62c8ad4..4e68104 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -281,17 +281,6 @@ def parse_unified_diff(diff: Optional[str] = None) -> Dict[str, Set[int]]: return parsed_paths -def is_windows() -> bool: - """Determine if we're running on Windows. - - :returns: - True if running on Windows, otherwise False - :rtype: - bool - """ - return os.name == "nt" - - def is_using_stdin(paths: List[str]) -> bool: """Determine if we're going to read from stdin. diff --git a/tests/unit/test_option.py b/tests/unit/test_option.py index 52aef27..d576c49 100644 --- a/tests/unit/test_option.py +++ b/tests/unit/test_option.py @@ -25,14 +25,6 @@ def test_to_argparse(): assert isinstance(kwargs["type"], functools.partial) -def test_to_optparse(): - """Test that .to_optparse() produces a useful error message.""" - with pytest.raises(AttributeError) as excinfo: - manager.Option("--foo").to_optparse - (msg,) = excinfo.value.args - assert msg == "to_optparse: flake8 now uses argparse" - - def test_to_argparse_creates_an_option_as_we_expect(): """Show that we pass all keyword args to argparse.""" opt = manager.Option("-t", "--test", action="count") diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 22bb44d..947b67f 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -160,15 +160,6 @@ def test_normalize_paths(value, expected): assert utils.normalize_paths(value) == expected -def test_is_windows_checks_for_nt(): - """Verify that we correctly detect Windows.""" - with mock.patch.object(os, "name", "nt"): - assert utils.is_windows() is True - - with mock.patch.object(os, "name", "posix"): - assert utils.is_windows() is False - - @pytest.mark.parametrize( "filename,patterns,expected", [