@@ -140,11 +140,17 @@ function pyconvert_get_rules(type::Type, pytype::Py)
140
140
omro_ = filter (t -> pyisin (t, omro), mro)
141
141
@assert length (omro) == length (omro_)
142
142
@assert all (pyis (x,y) for (x,y) in zip (omro, omro_))
143
- # TODO : special cases (buffer protocol, etc.)
144
143
145
144
# get the names of the types in the MRO of pytype
146
145
mro = String[" $(t. __module__) /$(t. __qualname__) " for t in mro]
147
146
147
+ # add special names
148
+ # currently we don't care where they go because they are tested in their own priority (200)
149
+ pyhasattr (pytype, " __array_struct__" ) && push! (mro, " <arraystruct>" )
150
+ pyhasattr (pytype, " __array_interface__" ) && push! (mro, " <arrayinterface>" )
151
+ pyhasattr (pytype, " __array__" ) && push! (mro, " <array>" )
152
+ C. PyType_CheckBuffer (getptr (pytype)) && push! (mro, " <buffer>" )
153
+
148
154
# get corresponding rules
149
155
rules = PyConvertRule[rule for tname in mro for rule in get! (Vector{PyConvertRule}, PYCONVERT_RULES, tname)]
150
156
@@ -276,6 +282,10 @@ function init_pyconvert()
276
282
pyconvert_add_rule (" juliacall/As" , Any, pyconvert_rule_jlas, 300 )
277
283
pyconvert_add_rule (" juliacall/ValueBase" , Any, pyconvert_rule_jlvalue, 300 )
278
284
# priority 200: arrays
285
+ pyconvert_add_rule (" <arraystruct>" , AbstractArray, pyconvert_rule_array, 200 )
286
+ pyconvert_add_rule (" <arrayinterface>" , AbstractArray, pyconvert_rule_array, 200 )
287
+ pyconvert_add_rule (" <array>" , AbstractArray, pyconvert_rule_array, 200 )
288
+ pyconvert_add_rule (" <buffer>" , AbstractArray, pyconvert_rule_array, 200 )
279
289
# priority 100: canonical
280
290
pyconvert_add_rule (" builtins/NoneType" , Nothing, pyconvert_rule_none, 100 )
281
291
pyconvert_add_rule (" builtins/bool" , Bool, pyconvert_rule_bool, 100 )
0 commit comments