Skip to content

Commit

Permalink
Use type error codes in # type ignore
Browse files Browse the repository at this point in the history
Import JSONDecodeError unconditionally as it's available in all
supported Python versions
  • Loading branch information
srittau committed Oct 19, 2022
1 parent 2518a24 commit 3ca7965
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions test_asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from collections import OrderedDict
from datetime import datetime, timedelta
from json import JSONDecodeError
from unittest import TestCase
from warnings import catch_warnings, warn

Expand Down Expand Up @@ -277,7 +278,7 @@ def test_assert_almost_equal__not_similar__delta__custom_message(self):

def test_assert_almost_equal__wrong_types(self):
try:
assert_almost_equal("5", "5") # type: ignore
assert_almost_equal("5", "5") # type: ignore[arg-type]
except TypeError:
pass
else:
Expand Down Expand Up @@ -370,7 +371,7 @@ def test_assert_not_almost_equal__similar__delta__custom_message(self):

def test_assert_not_almost_equal__wrong_types(self):
try:
assert_not_almost_equal("5", "5") # type: ignore
assert_not_almost_equal("5", "5") # type: ignore[arg-type]
except TypeError:
pass
else:
Expand Down Expand Up @@ -1460,10 +1461,6 @@ def test_assert_json_subset__second_is_unsupported_json_string(self):
assert_json_subset({}, "42")

def test_assert_json_subset__second_is_invalid_json_string(self):
try:
from json import JSONDecodeError
except ImportError:
JSONDecodeError = ValueError # type: ignore
with assert_raises(JSONDecodeError):
assert_json_subset({}, ",")

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

def test_assert_json_subset__element_name_not_str(self) -> None:
with assert_raises_regex(
Expand Down

0 comments on commit 3ca7965

Please sign in to comment.