Skip to content

Commit 3ca7965

Browse files
committed
Use type error codes in # type ignore
Import JSONDecodeError unconditionally as it's available in all supported Python versions
1 parent 2518a24 commit 3ca7965

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

test_asserts.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from collections import OrderedDict
66
from datetime import datetime, timedelta
7+
from json import JSONDecodeError
78
from unittest import TestCase
89
from warnings import catch_warnings, warn
910

@@ -277,7 +278,7 @@ def test_assert_almost_equal__not_similar__delta__custom_message(self):
277278

278279
def test_assert_almost_equal__wrong_types(self):
279280
try:
280-
assert_almost_equal("5", "5") # type: ignore
281+
assert_almost_equal("5", "5") # type: ignore[arg-type]
281282
except TypeError:
282283
pass
283284
else:
@@ -370,7 +371,7 @@ def test_assert_not_almost_equal__similar__delta__custom_message(self):
370371

371372
def test_assert_not_almost_equal__wrong_types(self):
372373
try:
373-
assert_not_almost_equal("5", "5") # type: ignore
374+
assert_not_almost_equal("5", "5") # type: ignore[arg-type]
374375
except TypeError:
375376
pass
376377
else:
@@ -1460,10 +1461,6 @@ def test_assert_json_subset__second_is_unsupported_json_string(self):
14601461
assert_json_subset({}, "42")
14611462

14621463
def test_assert_json_subset__second_is_invalid_json_string(self):
1463-
try:
1464-
from json import JSONDecodeError
1465-
except ImportError:
1466-
JSONDecodeError = ValueError # type: ignore
14671464
with assert_raises(JSONDecodeError):
14681465
assert_json_subset({}, ",")
14691466

@@ -1479,7 +1476,7 @@ def test_assert_json_subset__invalid_type(self):
14791476
with assert_raises_regex(
14801477
TypeError, "second must be dict, list, str, or bytes"
14811478
):
1482-
assert_json_subset({}, 42) # type: ignore
1479+
assert_json_subset({}, 42) # type: ignore[arg-type]
14831480

14841481
def test_assert_json_subset__element_name_not_str(self) -> None:
14851482
with assert_raises_regex(

0 commit comments

Comments
 (0)