How to use the nitpick.generic.flatten function in nitpick

To help you get started, we’ve selected a few nitpick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andreoliwa / nitpick / src / nitpick / plugins / json.py View on Github external
def get_suggested_json(self, raw_actual: JsonDict = None) -> JsonDict:
        """Return the suggested JSON based on actual values."""
        actual = set(flatten(raw_actual).keys()) if raw_actual else set()
        expected = set(self.file_dict.get(KEY_CONTAINS_KEYS) or [])
        # TODO: include "contains_json" keys in the suggestion as well
        missing = expected - actual
        if not missing:
            return {}

        return SortedDict(unflatten({key: self.SOME_VALUE_PLACEHOLDER for key in missing}))
github andreoliwa / nitpick / src / nitpick / formats.py View on Github external
def _normalize_value(value: Union[JsonDict, YamlData, "BaseFormat"]) -> JsonDict:
        if isinstance(value, BaseFormat):
            dict_value = value.as_data  # type: JsonDict
        else:
            dict_value = value
        return flatten(dict_value)
github andreoliwa / nitpick / src / nitpick / schemas.py View on Github external
def flatten_marshmallow_errors(errors: Dict) -> str:
    """Flatten Marshmallow errors to a string."""
    formatted = []
    for field, data in SortedDict(flatten(errors)).items():
        if isinstance(data, list):
            messages_per_field = ["{}: {}".format(field, ", ".join(data))]
        elif isinstance(data, dict):
            messages_per_field = [
                "{}[{}]: {}".format(field, index, ", ".join(messages)) for index, messages in data.items()
            ]
        else:
            # This should never happen; if it does, let's just convert to a string
            messages_per_field = [str(errors)]
        formatted.append("\n".join(messages_per_field))
    return "\n".join(formatted)