Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 4, 2024
1 parent 26a5522 commit 39c3eab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
32 changes: 16 additions & 16 deletions src/typeguard/_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,22 @@ def check_class(
elif get_origin(expected_class) is Union:
errors: dict[str, TypeCheckError] = {}
try:
for arg in get_args(expected_class):
if arg is Any:
return

try:
check_class(value, type, (arg,), memo)
return
except TypeCheckError as exc:
errors[get_type_name(arg)] = exc
else:
formatted_errors = indent(
"\n".join(f"{key}: {error}" for key, error in errors.items()), " "
)
raise TypeCheckError(
f"did not match any element in the union:\n{formatted_errors}"
)
for arg in get_args(expected_class):
if arg is Any:
return

try:
check_class(value, type, (arg,), memo)
return
except TypeCheckError as exc:
errors[get_type_name(arg)] = exc
else:
formatted_errors = indent(
"\n".join(f"{key}: {error}" for key, error in errors.items()), " "
)
raise TypeCheckError(
f"did not match any element in the union:\n{formatted_errors}"
)
finally:
del errors # avoid creating ref cycle
elif not issubclass(value, expected_class): # type: ignore[arg-type]
Expand Down
5 changes: 2 additions & 3 deletions tests/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,8 @@ def inner3():
@pytest.mark.skipif(
sys.implementation.name != "cpython",
reason="Test relies on CPython's reference counting behavior",
)
@pytest.mark.skipif(
sys.version_info < (3, 10), reason="UnionType requires 3.10"
)
@pytest.mark.skipif(sys.version_info < (3, 10), reason="UnionType requires 3.10")
def test_uniontype_reference_leak(self):
class Leak:
def __del__(self):
Expand Down Expand Up @@ -892,6 +890,7 @@ def inner3():
inner3()
assert not leaked


class TestTypevar:
def test_bound(self):
check_type(Child(), TParent)
Expand Down

0 comments on commit 39c3eab

Please sign in to comment.