Skip to content

Commit

Permalink
chore: remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Jan 7, 2022
1 parent a835796 commit 6c228d7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 50 deletions.
39 changes: 1 addition & 38 deletions src/nitpick/documents.py
Expand Up @@ -3,13 +3,12 @@
import json
from collections import OrderedDict
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import Any, Dict, List, Optional, Tuple, Type, Union

import dictdiffer
import toml
import tomlkit
from autorepr import autorepr
from loguru import logger
from more_itertools import always_iterable
from ruamel.yaml import YAML, RoundTripRepresenter, StringIO
from ruamel.yaml.comments import CommentedMap, CommentedSeq
Expand Down Expand Up @@ -152,25 +151,6 @@ def _normalize_value(value: JsonDict) -> Dict:
dict_value = value
return flatten(dict_value)

def update_pair(self, key, raw_expected):
"""Update a key on one of the comparison dicts, with its raw expected value."""
if isinstance(key, str):
self.diff_dict.update({key: raw_expected})
return

if isinstance(key, list):
if len(key) == 4 and isinstance(key[3], int):
_, _, new_key, index = key
if new_key not in self.diff_dict:
self.diff_dict[new_key] = []
self.diff_dict[new_key].insert(index, raw_expected)
return
if len(key) == 1:
self.diff_dict.update(unflatten({key[0]: raw_expected}))
return

logger.warning("Err... this is unexpected, please open an issue: key={} raw_expected={}", key, raw_expected)


class BaseDoc(metaclass=abc.ABCMeta):
"""Base class for configuration file formats.
Expand Down Expand Up @@ -285,23 +265,6 @@ def compare_with_flatten(self, expected: JsonDict = None, unique_keys: JsonDict
comparison.replace_dict = unflatten(replace)
return comparison

def compare_with_dictdiffer(self, expected: JsonDict = None, transform_function: Callable = None) -> Comparison:
"""Compare two structures and compute missing and different items using ``dictdiffer``."""
comparison = self._create_comparison(expected or {})

missing_dict = SortedDict()
for diff_type, key, values in dictdiffer.diff(comparison.flat_actual, comparison.flat_expected):
if diff_type == dictdiffer.ADD:
missing_dict.update(dict(values))
elif diff_type == dictdiffer.CHANGE:
raw_actual, raw_expected = values
actual_value, expected_value = comparison.doc_class.cleanup(raw_actual, raw_expected)
if actual_value != expected_value:
comparison.update_pair(key, raw_expected)

comparison.missing_dict = transform_function(missing_dict) if transform_function else missing_dict
return comparison


class InlineTableTomlDecoder(toml.TomlDecoder): # type: ignore[name-defined]
"""A hacky decoder to work around some bug (or unfinished work) in the Python TOML package.
Expand Down
12 changes: 1 addition & 11 deletions src/nitpick/plugins/base.py
Expand Up @@ -10,7 +10,7 @@
from marshmallow import Schema

from nitpick.constants import DUNDER_SEARCH_UNIQUE_KEY
from nitpick.documents import BaseDoc, Comparison
from nitpick.documents import BaseDoc
from nitpick.generic import search_dict
from nitpick.plugins.info import FileInfo
from nitpick.typedefs import JsonDict, mypy_property
Expand Down Expand Up @@ -147,13 +147,3 @@ def write_initial_contents(self, doc_class: Type[BaseDoc], expected_dict: Dict =
self.file_path.parent.mkdir(exist_ok=True, parents=True)
self.file_path.write_text(formatted_str)
return formatted_str

def warn_missing_different(self, comparison: Comparison, prefix: str = "") -> Iterator[Fuss]:
"""Warn about missing and different keys."""
# pylint: disable=not-callable
if comparison.missing:
yield self.reporter.make_fuss(
SharedViolations.MISSING_VALUES, comparison.missing.reformatted, prefix=prefix
)
if comparison.diff:
yield self.reporter.make_fuss(SharedViolations.DIFFERENT_VALUES, comparison.diff.reformatted, prefix=prefix)
1 change: 0 additions & 1 deletion src/nitpick/typedefs.py
Expand Up @@ -11,7 +11,6 @@
StrOrIterable = Union[str, Iterable[str]]
Flake8Error = Tuple[int, int, str, Type]
YamlObject = Union[CommentedSeq, CommentedMap]

YamlValue = Union[JsonDict, OrderedDict, List[Any], str, float]

# Decorated property not supported · Issue #1362 · python/mypy
Expand Down

0 comments on commit 6c228d7

Please sign in to comment.