@@ -46,12 +46,12 @@ def check_type(
4646 expected_type : Any ,
4747) -> None :
4848 """Ensure that value matches expected_type, alias for typeguard.check_type."""
49- if True : # Typeguard not yet supported
50- return
5149 return typeguard .check_type (value , expected_type )
5250
5351
54- exc_cls = Exception
52+ exc_cls = typeguard .TypeCheckError
53+
54+
5555class TypeCheckError (exc_cls ):
5656 """Indicates a runtime typechecking error from the @typechecked decorator."""
5757
@@ -112,9 +112,6 @@ def _annotation_repr(ann: Any) -> str:
112112
113113def typechecked (fn ):
114114 """Decorator to enable runtime type-checking and shape-checking."""
115- if True : # Typeguard not yet supported
116- return fn
117-
118115 if hasattr (fn , "__wrapped__" ):
119116 raise AssertionError ("@typechecked should be the innermost decorator" )
120117
@@ -126,17 +123,29 @@ def _reraise_with_shape_info(*args, _typecheck: bool = True, **kwargs):
126123 # typchecking disabled globally or locally -> just return fn(...)
127124 return fn (* args , ** kwargs )
128125
129- # Find either the first Python wrapper or the actual function
130- python_func = inspect . unwrap ( fn , stop = lambda f : hasattr ( f , "__code__" ) )
126+ sig = inspect . signature ( fn )
127+ bound_args = sig . bind ( * args , ** kwargs )
131128 # manually reproduce the functionality of typeguard.typechecked, so that
132129 # we get access to the returnvalue of the function
133130 localns = sys ._getframe (1 ).f_locals # pylint: disable=protected-access
134- memo = typeguard .CallMemo (python_func , localns , args = args , kwargs = kwargs )
131+ globalns = sys ._getframe (1 ).f_globals # pylint: disable=protected-access
132+ memo = typeguard .TypeCheckMemo (globalns , localns )
135133 retval = _undef
134+ annotated_arguments = {
135+ k : (v , sig .parameters [k ].annotation )
136+ for k , v in bound_args .arguments .items ()
137+ if sig .parameters [k ].annotation != inspect .Parameter .empty
138+ }
139+
136140 try :
137- typeguard .check_argument_types (memo )
141+ typeguard ._functions .check_argument_types ( # pylint: disable=protected-access
142+ fn .__name__ , annotated_arguments , memo = memo
143+ )
138144 retval = fn (* args , ** kwargs )
139- typeguard .check_return_type (retval , memo )
145+ if sig .return_annotation is not inspect .Parameter .empty :
146+ typeguard ._functions .check_return_type ( # pylint: disable=protected-access
147+ fn .__name__ , retval , sig .return_annotation , memo
148+ )
140149 return retval
141150 except typeguard .TypeCheckError as e :
142151 # Use function signature to construct a complete list of named arguments
@@ -396,7 +405,7 @@ def _custom_dataclass_checker(
396405 dataclass_as_typed_dict .__module__ = origin_type .__module__
397406 values = {k .name : getattr (value , k .name ) for k in fields }
398407 try :
399- return typeguard .check_type (
408+ return typeguard .check_type_internal (
400409 dataclass_as_typed_dict (** values ),
401410 dataclass_as_typed_dict ,
402411 memo = memo ,
@@ -469,3 +478,7 @@ def add_custom_checker_lookup_fn(lookup_fn):
469478 break
470479 else : # prepend
471480 checker_lookup_fns [:0 ] = [lookup_fn ]
481+
482+
483+ add_custom_checker_lookup_fn (_array_spec_checker_lookup )
484+ add_custom_checker_lookup_fn (_dataclass_checker_lookup )
0 commit comments