@@ -1969,24 +1969,39 @@ int py_loader_impl_clear(loader_impl impl, loader_handle handle)
19691969 return 1 ;
19701970}
19711971
1972- type py_loader_impl_discover_type (loader_impl impl , PyObject * annotation )
1972+ type py_loader_impl_discover_type (loader_impl impl , PyObject * annotation , const char * func_name , const char * parameter_name )
19731973{
19741974 type t = NULL ;
19751975
19761976 if (annotation != NULL )
19771977 {
1978- PyObject * annotation_qualname = PyObject_GetAttrString ( annotation , "__qualname__" ) ;
1978+ static const char qualname [] = "__qualname__" ;
19791979
1980+ if (PyObject_HasAttrString (annotation , qualname ) == 0 )
1981+ {
1982+ if (parameter_name != NULL )
1983+ {
1984+ log_write ("metacall" , LOG_LEVEL_WARNING , "Invalid annotation type in the parameter '%s' of the function %s" , parameter_name , func_name );
1985+ }
1986+ else
1987+ {
1988+ log_write ("metacall" , LOG_LEVEL_WARNING , "Invalid annotation type in the return type of the function %s" , func_name );
1989+ }
1990+
1991+ return NULL ;
1992+ }
1993+
1994+ PyObject * annotation_qualname = PyObject_GetAttrString (annotation , qualname );
19801995 const char * annotation_name = PyUnicode_AsUTF8 (annotation_qualname );
19811996
19821997 if (strcmp (annotation_name , "_empty" ) != 0 )
19831998 {
19841999 t = loader_impl_type (impl , annotation_name );
19852000
19862001 log_write ("metacall" , LOG_LEVEL_DEBUG , "Discover type (%p) (%p): %s" , (void * )annotation , (void * )type_derived (t ), annotation_name );
1987-
1988- Py_DECREF (annotation_qualname );
19892002 }
2003+
2004+ Py_DECREF (annotation_qualname );
19902005 }
19912006
19922007 return t ;
@@ -2074,6 +2089,8 @@ int py_loader_impl_discover_func(loader_impl impl, PyObject *func, function f)
20742089 {
20752090 signature s = function_signature (f );
20762091
2092+ const char * func_name = function_name (f );
2093+
20772094 PyObject * parameters = PyObject_GetAttrString (result , "parameters" );
20782095
20792096 PyObject * return_annotation = PyObject_GetAttrString (result , "return_annotation" );
@@ -2111,15 +2128,15 @@ int py_loader_impl_discover_func(loader_impl impl, PyObject *func, function f)
21112128
21122129 PyObject * annotation = PyObject_GetAttrString (parameter , "annotation" );
21132130
2114- type t = py_loader_impl_discover_type (impl , annotation );
2131+ type t = py_loader_impl_discover_type (impl , annotation , func_name , parameter_name );
21152132
21162133 signature_set (s , iterator , parameter_name , t );
21172134 }
21182135 }
21192136 }
21202137 }
21212138
2122- signature_set_return (s , py_loader_impl_discover_type (impl , return_annotation ));
2139+ signature_set_return (s , py_loader_impl_discover_type (impl , return_annotation , func_name , NULL ));
21232140
21242141 return 0 ;
21252142 }
0 commit comments