From 5edb5a59b133b52489d6a1c73afd83c9342b14e6 Mon Sep 17 00:00:00 2001 From: v-chen_data Date: Fri, 27 Sep 2024 12:48:29 -0700 Subject: [PATCH] precommit --- tests/utils/test_exceptions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/utils/test_exceptions.py b/tests/utils/test_exceptions.py index 44c6354998..564dfa2f14 100644 --- a/tests/utils/test_exceptions.py +++ b/tests/utils/test_exceptions.py @@ -4,7 +4,7 @@ import contextlib import inspect import pickle -from typing import Any, Optional +from typing import Any, Optional, get_type_hints import pytest @@ -16,10 +16,11 @@ def create_exception_object( ): def get_init_annotations(cls: type): - if hasattr(inspect, 'get_annotations'): - return inspect.get_annotations(cls.__init__) - else: - return getattr(cls.__init__, '__annotations__', {}) + try: + return get_type_hints(cls.__init__) + except (AttributeError, TypeError): + # Handle cases where __init__ does not exist or has no annotations + return {} # First, try to get annotations from the class itself required_args = get_init_annotations(exception_class)