2
2
3
3
from cpython.object cimport Py_EQ, Py_NE
4
4
from libc.stdint cimport intptr_t
5
+ from libcpp.map cimport map
5
6
from libcpp.string cimport string
6
7
7
8
from ..cpp.types.type_id cimport (type_id_t, uninitialized_type_id,
@@ -24,24 +25,14 @@ from ..cpp.types.var_dim_type cimport dynd_make_var_dim_type
24
25
from ..cpp.types.tuple_type cimport make_tuple as _make_tuple
25
26
from ..cpp.types.struct_type cimport make_struct as _make_struct
26
27
from ..cpp.types.callable_type cimport make_callable
28
+ from ..cpp.func.callable cimport callable as _callable
27
29
28
30
from ..config cimport translate_exception
29
31
from ..wrapper cimport set_wrapper_type, wrap
30
32
31
33
cdef extern from " numpy_interop.hpp" namespace " pydynd" :
32
34
object numpy_dtype_obj_from__type(_type& ) except + translate_exception
33
35
34
- cdef extern from ' gfunc_callable_functions.hpp' namespace ' pydynd' :
35
- void add_type_names_to_dir_dict(_type& , object ) except + translate_exception
36
- object get__type_dynamic_property(_type& , object ) except + translate_exception
37
-
38
- # Function properties
39
- cdef cppclass _type_callable_wrapper:
40
- pass
41
- object _type_callable_call(_type_callable_wrapper& , object , object ) except + translate_exception
42
-
43
- void init_w__type_callable_typeobject(object )
44
-
45
36
cdef extern from ' type_functions.hpp' namespace ' pydynd' :
46
37
void init_w_type_typeobject(object )
47
38
@@ -219,7 +210,24 @@ cdef class type(object):
219
210
return _type_get_type_id(self .v)
220
211
221
212
def __getattr__ (self , name ):
222
- return get__type_dynamic_property(self .v, name)
213
+ if self .v.is_null():
214
+ raise AttributeError (name)
215
+
216
+ cdef _callable p
217
+ cdef map [string, _callable] properties
218
+ cdef map [string, _callable] functions
219
+ cdef _callable f
220
+ if (not self .v.is_builtin()):
221
+ self .v.get().get_dynamic_type_properties(properties)
222
+ p = properties[name]
223
+ if (not p.is_null()):
224
+ return wrap(p(self .v))
225
+ self .v.get().get_dynamic_type_functions(functions)
226
+ f = functions[name]
227
+ if (not f.is_null()):
228
+ return wrap(f(self .v))
229
+
230
+ raise AttributeError (name)
223
231
224
232
def __str__ (self ):
225
233
return str (< char * > _type_str(self .v).c_str())
@@ -288,14 +296,6 @@ cdef type dynd_ndt_type_from_cpp(_type t):
288
296
289
297
set_wrapper_type[_type](type )
290
298
291
- cdef class type_callable:
292
- cdef _type_callable_wrapper v
293
-
294
- def __call__ (self , *args , **kwargs ):
295
- return _type_callable_call(self .v, args, kwargs)
296
-
297
- init_w__type_callable_typeobject(type_callable)
298
-
299
299
class UnsuppliedType (object ):
300
300
pass
301
301
0 commit comments