Skip to content

Commit

Permalink
Remove type ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Aug 22, 2024
1 parent 5f07d8a commit 9d25724
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 46 deletions.
15 changes: 5 additions & 10 deletions src/jsonyx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ class Encoder:
:type trailing_comma: bool, optional
"""

# pylint: disable-next=R0913
def __init__( # noqa: PLR0913
def __init__(
self,
*,
allow: _AllowList = NOTHING,
Expand Down Expand Up @@ -452,8 +451,7 @@ def loads(
)


# pylint: disable-next=R0913
def write( # noqa: PLR0913
def write(
obj: object,
filename: StrPath,
*,
Expand Down Expand Up @@ -514,8 +512,7 @@ def write( # noqa: PLR0913
).write(obj, filename)


# pylint: disable-next=R0913
def dump( # noqa: PLR0913
def dump(
obj: object,
fp: SupportsWrite[str] = stdout,
*,
Expand Down Expand Up @@ -575,8 +572,7 @@ def dump( # noqa: PLR0913
).dump(obj, fp)


# pylint: disable-next=R0913
def dumps( # noqa: PLR0913
def dumps(
obj: object,
*,
allow: _AllowList = NOTHING,
Expand Down Expand Up @@ -665,8 +661,7 @@ def apply_patch(
)


# pylint: disable-next=R0913
def run_select_query( # noqa: PLR0913
def run_select_query(
nodes: _Node | list[_Node],
query: str,
*,
Expand Down
21 changes: 6 additions & 15 deletions src/jsonyx/_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class JSONSyntaxError(SyntaxError):
:type end: int, optional
"""

# pylint: disable-next=R0913
def __init__(
self, msg: str, filename: str, doc: str, start: int, end: int = 0,
) -> None:
Expand Down Expand Up @@ -187,12 +186,11 @@ def __str__(self) -> str:
_errmsg: type[JSONSyntaxError] = JSONSyntaxError


try: # noqa: PLR1702
try:
if not TYPE_CHECKING:
from _jsonyx import make_scanner
except ImportError:
# pylint: disable-next=R0915, R0913, R0914
def make_scanner( # noqa: C901, PLR0915, PLR0917, PLR0913
def make_scanner(
allow_comments: bool, # noqa: FBT001
allow_duplicate_keys: bool, # noqa: FBT001
allow_missing_commas: bool, # noqa: FBT001
Expand Down Expand Up @@ -236,10 +234,7 @@ def skip_comments(filename: str, s: str, end: int) -> int:
msg = "Comments are not allowed"
raise _errmsg(msg, filename, s, comment_idx, end)

# pylint: disable-next=R0912, R0915
def scan_string( # noqa: C901, PLR0912, PLR0915
filename: str, s: str, end: int,
) -> tuple[str, int]:
def scan_string(filename: str, s: str, end: int) -> tuple[str, int]:
chunks: list[str] = []
append_chunk: Callable[[str], None] = chunks.append
str_idx: int = end - 1
Expand Down Expand Up @@ -314,8 +309,7 @@ def scan_string( # noqa: C901, PLR0912, PLR0915

append_chunk(char)

# pylint: disable-next=R0913, R0912, R0915
def scan_object( # noqa: C901, PLR0912, PLR0915
def scan_object(
filename: str, s: str, end: int,
) -> tuple[dict[str, Any], int]:
obj_idx: int = end - 1
Expand Down Expand Up @@ -393,7 +387,7 @@ def scan_object( # noqa: C901, PLR0912, PLR0915

return result, end + 1

def scan_array( # noqa: C901
def scan_array(
filename: str, s: str, end: int,
) -> tuple[list[Any], int]:
arr_idx: int = end - 1
Expand Down Expand Up @@ -447,10 +441,7 @@ def scan_array( # noqa: C901

return values, end + 1

# pylint: disable-next=R0912, R0915
def scan_value( # noqa: C901, PLR0912
filename: str, s: str, idx: int,
) -> tuple[Any, int]:
def scan_value(filename: str, s: str, idx: int) -> tuple[Any, int]:
try:
nextchar = s[idx]
except IndexError:
Expand Down
8 changes: 4 additions & 4 deletions src/jsonyx/_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _get_lcs(old: list[Any], new: list[Any]) -> list[Any]:
return lcs[::-1]


def _diff( # noqa: C901
def _make_patch(
old: Any, new: Any, patch: list[dict[str, Any]], path: str = "$",
) -> None:
if _eq(old, new):
Expand All @@ -86,7 +86,7 @@ def _diff( # noqa: C901

for key in old_keys & new_keys:
new_path = f"{path}.{_escape(_replace, key)}"
_diff(old[key], new[key], patch, new_path)
_make_patch(old[key], new[key], patch, new_path)
elif isinstance(old, list) and isinstance(new, list):
lcs: list[Any] = _get_lcs(old, new) # type: ignore
old_idx = new_idx = lcs_idx = 0
Expand All @@ -99,7 +99,7 @@ def _diff( # noqa: C901
lcs_idx >= len(lcs) or not _eq(new[new_idx], lcs[lcs_idx])
)
if removed and inserted:
_diff(old[old_idx], new[new_idx], patch, new_path)
_make_patch(old[old_idx], new[new_idx], patch, new_path)
old_idx += 1
new_idx += 1
elif removed and not inserted:
Expand Down Expand Up @@ -135,7 +135,7 @@ def make_patch(old: Any, new: Any) -> list[dict[str, Any]]:
.. versionadded:: 2.0
"""
patch: list[dict[str, Any]] = []
_diff(old, new, patch)
_make_patch(old, new, patch)
return patch


Expand Down
3 changes: 1 addition & 2 deletions src/jsonyx/_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
if not TYPE_CHECKING:
from _jsonyx import make_encoder
except ImportError:
# pylint: disable-next=R0915, R0913, R0914
def make_encoder( # noqa: C901, PLR0915, PLR0917, PLR0913
def make_encoder(
encode_decimal: Callable[[Decimal], str],
indent: str | None,
end: str,
Expand Down
15 changes: 4 additions & 11 deletions src/jsonyx/_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def _scan_query_string(s: str, end: int) -> tuple[str, int]:
append_chunk(esc)


# pylint: disable-next=R0915
class Manipulator:
"""JSON manipulator.
Expand All @@ -180,10 +179,7 @@ def __init__(
] = Decimal if use_decimal else float
self._use_decimal: bool = use_decimal

# pylint: disable-next=R0912
def _scan_query_value( # noqa: C901, PLR0912
self, s: str, idx: int = 0,
) -> tuple[Any, int]:
def _scan_query_value(self, s: str, idx: int = 0) -> tuple[Any, int]:
try:
nextchar: str = s[idx]
except IndexError:
Expand Down Expand Up @@ -278,8 +274,7 @@ def _run_filter_query(

end += 2

# pylint: disable-next=R0912, R0913
def _run_select_query( # noqa: C901, PLR0912, PLR0913
def _run_select_query(
self,
nodes: list[_Node],
query: str,
Expand Down Expand Up @@ -355,7 +350,7 @@ def _run_select_query( # noqa: C901, PLR0912, PLR0913

return nodes, end

def _paste_values( # noqa: C901
def _paste_values(
self,
current_nodes: list[_Node],
operation: dict[str, Any],
Expand Down Expand Up @@ -413,8 +408,7 @@ def _paste_values( # noqa: C901
else:
raise ValueError

# pylint: disable-next=R0912, R0915, R0914
def _apply_patch( # noqa: C901, PLR0912, PLR0915
def _apply_patch(
self, root: list[Any], operations: list[dict[str, Any]],
) -> None:
node: _Node = root, 0
Expand Down Expand Up @@ -557,7 +551,6 @@ def apply_patch(
self._apply_patch(root, patch)
return root[0]

# pylint: disable-next=R0913
def run_select_query(
self,
nodes: _Node | list[_Node],
Expand Down
6 changes: 2 additions & 4 deletions src/jsonyx/test/test_syntax_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
# ^^^^^^^^^^^
],
)
# pylint: disable-next=R0913
def test_start_and_end_position( # noqa: PLR0913, PLR0917
def test_start_and_end_position(
doc: str, start: int, end: int, lineno: int, end_lineno: int,
end_colno: int,
) -> None:
Expand Down Expand Up @@ -140,8 +139,7 @@ def test_start_and_end_position( # noqa: PLR0913, PLR0917
# ^^^^ ^^^^
],
)
# pylint: disable-next=R0913
def test_err_context( # noqa: PLR0913, PLR0917
def test_err_context(
monkeypatch: pytest.MonkeyPatch, columns: int, doc: str, start: int,
end: int, offset: int, text: str, end_offset: int,
) -> None:
Expand Down

0 comments on commit 9d25724

Please sign in to comment.