Skip to content

Commit 9815074

Browse files
fix: add ty: ignore comments to suppress ty type checker diagnostics
Add suppression comments for: - unresolved-import: optional json2xml_rs Rust extension (guarded by try/except) - invalid-argument-type: tests intentionally passing wrong types - invalid-assignment: tests monkey-patching module functions Amp-Thread-ID: https://ampcode.com/threads/T-019d2ab6-a3d1-70a9-b3f7-c65e5c9199ab Co-authored-by: Amp <amp@ampcode.com>
1 parent 18de28e commit 9815074

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

json2xml/dicttoxml_fast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
_rust_dicttoxml = None
2525

2626
try:
27-
from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] # pragma: no cover
28-
from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] # pragma: no cover
29-
from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] # pragma: no cover
27+
from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
28+
from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
29+
from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
3030
_USE_RUST = True # pragma: no cover
3131
LOG.debug("Using Rust backend for dicttoxml") # pragma: no cover
3232
except ImportError: # pragma: no cover

tests/test_dict2xml.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class CustomClass:
578578

579579
# Should return the class name for unsupported types
580580
# Using type: ignore for intentional test of unsupported type
581-
result = dicttoxml.get_xml_type(CustomClass()) # type: ignore[arg-type]
581+
result = dicttoxml.get_xml_type(CustomClass()) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
582582
assert result == "CustomClass"
583583

584584
def test_make_valid_xml_name_invalid_chars(self) -> None:
@@ -807,8 +807,8 @@ def patched_get_unique_id(element: str) -> str:
807807
this_id = module.make_id(element) # This exercises line 52
808808
return ids[-1]
809809

810-
module.make_id = mock_make_id # type: ignore[assignment]
811-
module.get_unique_id = patched_get_unique_id # type: ignore[assignment]
810+
module.make_id = mock_make_id # type: ignore[assignment] # ty: ignore[invalid-assignment]
811+
module.get_unique_id = patched_get_unique_id # type: ignore[assignment] # ty: ignore[invalid-assignment]
812812

813813
try:
814814
result = dicttoxml.get_unique_id("test")
@@ -874,7 +874,7 @@ class CustomClass:
874874

875875
with pytest.raises(TypeError, match="Unsupported data type:"):
876876
dicttoxml.convert(
877-
obj=CustomClass(), # type: ignore[arg-type]
877+
obj=CustomClass(), # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
878878
ids=None,
879879
attr_type=False,
880880
item_func=lambda x: "item",
@@ -1024,7 +1024,7 @@ def mock_is_primitive(val: Any) -> bool:
10241024
return True
10251025
return original_is_primitive(val)
10261026

1027-
module.is_primitive_type = mock_is_primitive # type: ignore[assignment]
1027+
module.is_primitive_type = mock_is_primitive # type: ignore[assignment] # ty: ignore[invalid-assignment]
10281028
try:
10291029
item = {"@val": {"test": "data"}}
10301030
result = dicttoxml.dict2xml_str(

tests/test_json2xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ def test_read_from_jsonstring(self) -> None:
5656

5757
def test_read_from_invalid_string1(self) -> None:
5858
with pytest.raises(StringReadError) as pytest_wrapped_e:
59-
readfromstring(1) # type: ignore[arg-type]
59+
readfromstring(1) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
6060
assert pytest_wrapped_e.type == StringReadError
6161

6262
def test_read_from_invalid_string2(self) -> None:
6363
with pytest.raises(StringReadError) as pytest_wrapped_e:
64-
readfromstring(jsondata=None) # type: ignore[arg-type]
64+
readfromstring(jsondata=None) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
6565
assert pytest_wrapped_e.type == StringReadError
6666

6767
def test_read_from_invalid_jsonstring(self) -> None:

tests/test_rust_dicttoxml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
# Check if Rust extension is available
1414
try:
15-
from json2xml_rs import dicttoxml as rust_dicttoxml # type: ignore[import-not-found]
16-
from json2xml_rs import escape_xml_py, wrap_cdata_py # type: ignore[import-not-found]
15+
from json2xml_rs import dicttoxml as rust_dicttoxml # type: ignore[import-not-found] # ty: ignore[unresolved-import]
16+
from json2xml_rs import escape_xml_py, wrap_cdata_py # type: ignore[import-not-found] # ty: ignore[unresolved-import]
1717
RUST_AVAILABLE = True
1818
except ImportError:
1919
RUST_AVAILABLE = False

tests/test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,22 @@ def test_readfromstring_complex_object(self) -> None:
225225
def test_readfromstring_invalid_type_int(self) -> None:
226226
"""Test reading with integer input."""
227227
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
228-
readfromstring(123) # type: ignore[arg-type]
228+
readfromstring(123) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
229229

230230
def test_readfromstring_invalid_type_list(self) -> None:
231231
"""Test reading with list input."""
232232
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
233-
readfromstring(["not", "a", "string"]) # type: ignore[arg-type]
233+
readfromstring(["not", "a", "string"]) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
234234

235235
def test_readfromstring_invalid_type_dict(self) -> None:
236236
"""Test reading with dict input."""
237237
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
238-
readfromstring({"not": "a string"}) # type: ignore[arg-type]
238+
readfromstring({"not": "a string"}) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
239239

240240
def test_readfromstring_invalid_type_none(self) -> None:
241241
"""Test reading with None input."""
242242
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
243-
readfromstring(None) # type: ignore[arg-type]
243+
readfromstring(None) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
244244

245245
def test_readfromstring_invalid_json_syntax(self) -> None:
246246
"""Test reading string with invalid JSON syntax."""

0 commit comments

Comments
 (0)