Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/check_datapackage/exclude.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from typing import Any, Callable

from check_datapackage.internals import _filter, _map
from check_datapackage.issue import Issue


Expand Down Expand Up @@ -70,11 +70,3 @@ def _any_matching_types(issue: Issue, excludes: list[Exclude]) -> bool:

def _same_type(issue: Issue, exclude: Exclude) -> bool:
return exclude.type == issue.type


def _filter(x: Any, fn: Callable[[Any], bool]) -> list[Any]:
return list(filter(fn, x))


def _map(x: Any, fn: Callable[[Any], Any]) -> list[Any]:
return list(map(fn, x))
14 changes: 13 additions & 1 deletion src/check_datapackage/internals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Any, Iterator
from typing import Any, Callable, Iterable, Iterator, TypeVar

from jsonschema import Draft7Validator, FormatChecker, ValidationError

Expand Down Expand Up @@ -133,3 +133,15 @@ def _get_full_json_path_from_error(error: ValidationError) -> str:
if match:
return f"{error.json_path}.{match.group(1)}"
return error.json_path


In = TypeVar("In")
Out = TypeVar("Out")


def _map(x: Iterable[In], fn: Callable[[In], Out]) -> list[Out]:
return list(map(fn, x))


def _filter(x: Iterable[In], fn: Callable[[In], bool]) -> list[In]:
return list(filter(fn, x))