@@ -1969,24 +1969,39 @@ int py_loader_impl_clear(loader_impl impl, loader_handle handle)
1969
1969
return 1 ;
1970
1970
}
1971
1971
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 )
1973
1973
{
1974
1974
type t = NULL ;
1975
1975
1976
1976
if (annotation != NULL )
1977
1977
{
1978
- PyObject * annotation_qualname = PyObject_GetAttrString ( annotation , "__qualname__" ) ;
1978
+ static const char qualname [] = "__qualname__" ;
1979
1979
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 );
1980
1995
const char * annotation_name = PyUnicode_AsUTF8 (annotation_qualname );
1981
1996
1982
1997
if (strcmp (annotation_name , "_empty" ) != 0 )
1983
1998
{
1984
1999
t = loader_impl_type (impl , annotation_name );
1985
2000
1986
2001
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 );
1989
2002
}
2003
+
2004
+ Py_DECREF (annotation_qualname );
1990
2005
}
1991
2006
1992
2007
return t ;
@@ -2074,6 +2089,8 @@ int py_loader_impl_discover_func(loader_impl impl, PyObject *func, function f)
2074
2089
{
2075
2090
signature s = function_signature (f );
2076
2091
2092
+ const char * func_name = function_name (f );
2093
+
2077
2094
PyObject * parameters = PyObject_GetAttrString (result , "parameters" );
2078
2095
2079
2096
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)
2111
2128
2112
2129
PyObject * annotation = PyObject_GetAttrString (parameter , "annotation" );
2113
2130
2114
- type t = py_loader_impl_discover_type (impl , annotation );
2131
+ type t = py_loader_impl_discover_type (impl , annotation , func_name , parameter_name );
2115
2132
2116
2133
signature_set (s , iterator , parameter_name , t );
2117
2134
}
2118
2135
}
2119
2136
}
2120
2137
}
2121
2138
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 ));
2123
2140
2124
2141
return 0 ;
2125
2142
}
0 commit comments