@@ -47,6 +47,7 @@ include("dict.jl")
47
47
include (" set.jl" )
48
48
include (" buffer.jl" )
49
49
include (" collections.jl" )
50
+ include (" range.jl" )
50
51
51
52
__init__ () = begin
52
53
PyObject_TryConvert_AddRules (" builtins.NoneType" , [
@@ -56,30 +57,36 @@ __init__() = begin
56
57
PyObject_TryConvert_AddRules (" builtins.bool" , [
57
58
(Bool, PyBool_TryConvertRule_bool, 100 ),
58
59
])
59
- PyObject_TryConvert_AddRules (" builtins.int " , [
60
- (Integer, PyLong_TryConvertRule_integer , 100 ),
61
- (Rational, PyLong_TryConvertRule_tryconvert ),
62
- (Real, PyLong_TryConvertRule_tryconvert ),
63
- (Number, PyLong_TryConvertRule_tryconvert ),
64
- (Any, PyLong_TryConvertRule_tryconvert ),
60
+ PyObject_TryConvert_AddRules (" numbers.Integral " , [
61
+ (Integer, PyLongable_TryConvertRule_integer , 100 ),
62
+ (Rational, PyLongable_TryConvertRule_tryconvert ),
63
+ (Real, PyLongable_TryConvertRule_tryconvert ),
64
+ (Number, PyLongable_TryConvertRule_tryconvert ),
65
+ (Any, PyLongable_TryConvertRule_tryconvert ),
65
66
])
66
67
PyObject_TryConvert_AddRules (" builtins.float" , [
67
- (Float64, PyFloat_TryConvertRule_convert, 100 ),
68
- (BigFloat, PyFloat_TryConvertRule_convert),
69
- (Float32, PyFloat_TryConvertRule_convert),
70
- (Float16, PyFloat_TryConvertRule_convert),
71
- (AbstractFloat, PyFloat_TryConvertRule_tryconvert),
72
- (Real, PyFloat_TryConvertRule_tryconvert),
73
- (Number, PyFloat_TryConvertRule_tryconvert),
68
+ (Float64, PyFloatable_TryConvertRule_convert, 100 )
69
+ ])
70
+ PyObject_TryConvert_AddRules (" numbers.Real" , [
71
+ (Float64, PyFloatable_TryConvertRule_convert),
72
+ (BigFloat, PyFloatable_TryConvertRule_convert),
73
+ (Float32, PyFloatable_TryConvertRule_convert),
74
+ (Float16, PyFloatable_TryConvertRule_convert),
75
+ (AbstractFloat, PyFloatable_TryConvertRule_tryconvert),
76
+ (Real, PyFloatable_TryConvertRule_tryconvert),
77
+ (Number, PyFloatable_TryConvertRule_tryconvert),
74
78
])
75
79
PyObject_TryConvert_AddRules (" builtins.complex" , [
76
- (Complex{Float64}, PyComplex_TryConvertRule_convert, 100 ),
77
- (Complex{BigFloat}, PyComplex_TryConvertRule_convert),
78
- (Complex{Float32}, PyComplex_TryConvertRule_convert),
79
- (Complex{Float16}, PyComplex_TryConvertRule_convert),
80
- (Complex{T} where {T<: AbstractFloat }, PyComplex_TryConvertRule_tryconvert),
81
- (Complex{T} where {T<: Real }, PyComplex_TryConvertRule_tryconvert),
82
- (Number, PyComplex_TryConvertRule_tryconvert),
80
+ (Complex{Float64}, PyComplexable_TryConvertRule_convert, 100 ),
81
+ ])
82
+ PyObject_TryConvert_AddRules (" numbers.Complex" , [
83
+ (Complex{Float64}, PyComplexable_TryConvertRule_convert),
84
+ (Complex{BigFloat}, PyComplexable_TryConvertRule_convert),
85
+ (Complex{Float32}, PyComplexable_TryConvertRule_convert),
86
+ (Complex{Float16}, PyComplexable_TryConvertRule_convert),
87
+ (Complex{T} where {T<: AbstractFloat }, PyComplexable_TryConvertRule_tryconvert),
88
+ (Complex{T} where {T<: Real }, PyComplexable_TryConvertRule_tryconvert),
89
+ (Number, PyComplexable_TryConvertRule_tryconvert),
83
90
])
84
91
PyObject_TryConvert_AddRules (" builtins.bytes" , [
85
92
(Vector{UInt8}, PyBytes_TryConvertRule_vector),
@@ -96,6 +103,10 @@ __init__() = begin
96
103
PyObject_TryConvert_AddRules (" builtins.tuple" , [
97
104
(Tuple, PyIterable_ConvertRule_tuple, 100 ),
98
105
])
106
+ PyObject_TryConvert_AddRules (" builtins.range" , [
107
+ (StepRange{T,S} where {T<: Integer , S<: Integer }, PyRange_TryConvertRule_steprange, 100 ),
108
+ (UnitRange{T} where {T<: Integer }, PyRange_TryConvertRule_unitrange),
109
+ ])
99
110
PyObject_TryConvert_AddRules (" collections.abc.Iterable" , [
100
111
(Vector, PyIterable_ConvertRule_vector),
101
112
(Set, PyIterable_ConvertRule_set),
@@ -112,13 +123,37 @@ __init__() = begin
112
123
(Dict, PyMapping_ConvertRule_dict),
113
124
])
114
125
PyObject_TryConvert_AddExtraTypes ([
115
- (" collections.abc.Iterable" , PyIterableABC_SubclassCheck),
116
- (" collections.abc.Callable" , PyCallableABC_SubclassCheck),
117
- (" collections.abc.Sequence" , PySequenceABC_SubclassCheck),
118
- (" collections.abc.Mapping" , PyMappingABC_SubclassCheck),
119
- (" collections.abc.Set" , PySetABC_SubclassCheck),
120
- (" builtins.bufferable" , PyType_CheckBuffer),
126
+ PyIterableABC_Type,
127
+ PyCallableABC_Type,
128
+ PySequenceABC_Type,
129
+ PyMappingABC_Type,
130
+ PySetABC_Type,
131
+ PyNumberABC_Type,
132
+ PyComplexABC_Type,
133
+ PyRealABC_Type,
134
+ PyRationalABC_Type,
135
+ PyIntegralABC_Type,
121
136
])
137
+ # ## Numpy
138
+ # These aren't necessary but exist just to preserve the datatype.
139
+ # TODO : Access these types directly.
140
+ # TODO : Compound types?
141
+ PyObject_TryConvert_AddRule (" numpy.int8" , Int8, PyLongable_TryConvertRule_integer, 100 )
142
+ PyObject_TryConvert_AddRule (" numpy.int16" , Int16, PyLongable_TryConvertRule_integer, 100 )
143
+ PyObject_TryConvert_AddRule (" numpy.int32" , Int32, PyLongable_TryConvertRule_integer, 100 )
144
+ PyObject_TryConvert_AddRule (" numpy.int64" , Int64, PyLongable_TryConvertRule_integer, 100 )
145
+ PyObject_TryConvert_AddRule (" numpy.int128" , Int128, PyLongable_TryConvertRule_integer, 100 )
146
+ PyObject_TryConvert_AddRule (" numpy.uint8" , UInt8, PyLongable_TryConvertRule_integer, 100 )
147
+ PyObject_TryConvert_AddRule (" numpy.uint16" , UInt16, PyLongable_TryConvertRule_integer, 100 )
148
+ PyObject_TryConvert_AddRule (" numpy.uint32" , UInt32, PyLongable_TryConvertRule_integer, 100 )
149
+ PyObject_TryConvert_AddRule (" numpy.uint64" , UInt64, PyLongable_TryConvertRule_integer, 100 )
150
+ PyObject_TryConvert_AddRule (" numpy.uint128" , UInt128, PyLongable_TryConvertRule_integer, 100 )
151
+ PyObject_TryConvert_AddRule (" numpy.float16" , Float16, PyFloatable_TryConvertRule_convert, 100 )
152
+ PyObject_TryConvert_AddRule (" numpy.float32" , Float32, PyFloatable_TryConvertRule_convert, 100 )
153
+ PyObject_TryConvert_AddRule (" numpy.float64" , Float64, PyFloatable_TryConvertRule_convert, 100 )
154
+ PyObject_TryConvert_AddRule (" numpy.complex32" , Complex{Float16}, PyComplexable_TryConvertRule_convert, 100 )
155
+ PyObject_TryConvert_AddRule (" numpy.complex64" , Complex{Float32}, PyComplexable_TryConvertRule_convert, 100 )
156
+ PyObject_TryConvert_AddRule (" numpy.complex128" , Complex{Float64}, PyComplexable_TryConvertRule_convert, 100 )
122
157
end
123
158
124
159
end
0 commit comments