Skip to content

Commit 7f88ca7

Browse files
dbrattliclaude
andauthored
chore(python): use PyClassInitializer for typed array subclasses (#4666)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3171a69 commit 7f88ca7

1 file changed

Lines changed: 24 additions & 54 deletions

File tree

src/fable-library-py/src/array.rs

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,137 +5088,107 @@ impl FSharpCons {
50885088
impl Int8Array {
50895089
#[new]
50905090
#[pyo3(signature = (elements=None))]
5091-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5092-
Ok((Int8Array {}, FSharpArray::new(py, elements, Some("Int8"))?))
5091+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5092+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Int8"))?).add_subclass(Int8Array {}))
50935093
}
50945094
}
50955095

50965096
#[pymethods]
50975097
impl UInt8Array {
50985098
#[new]
50995099
#[pyo3(signature = (elements=None))]
5100-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5101-
Ok((
5102-
UInt8Array {},
5103-
FSharpArray::new(py, elements, Some("UInt8"))?,
5104-
))
5100+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5101+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("UInt8"))?).add_subclass(UInt8Array {}))
51055102
}
51065103
}
51075104

51085105
#[pymethods]
51095106
impl Int16Array {
51105107
#[new]
51115108
#[pyo3(signature = (elements=None))]
5112-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5113-
Ok((
5114-
Int16Array {},
5115-
FSharpArray::new(py, elements, Some("Int16"))?,
5116-
))
5109+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5110+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Int16"))?).add_subclass(Int16Array {}))
51175111
}
51185112
}
51195113

51205114
#[pymethods]
51215115
impl UInt16Array {
51225116
#[new]
51235117
#[pyo3(signature = (elements=None))]
5124-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5125-
Ok((
5126-
UInt16Array {},
5127-
FSharpArray::new(py, elements, Some("UInt16"))?,
5128-
))
5118+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5119+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("UInt16"))?).add_subclass(UInt16Array {}))
51295120
}
51305121
}
51315122

51325123
#[pymethods]
51335124
impl Int32Array {
51345125
#[new]
51355126
#[pyo3(signature = (elements=None))]
5136-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5137-
Ok((
5138-
Int32Array {},
5139-
FSharpArray::new(py, elements, Some("Int32"))?,
5140-
))
5127+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5128+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Int32"))?).add_subclass(Int32Array {}))
51415129
}
51425130
}
51435131

51445132
#[pymethods]
51455133
impl UInt32Array {
51465134
#[new]
51475135
#[pyo3(signature = (elements=None))]
5148-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5149-
Ok((
5150-
UInt32Array {},
5151-
FSharpArray::new(py, elements, Some("UInt32"))?,
5152-
))
5136+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5137+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("UInt32"))?).add_subclass(UInt32Array {}))
51535138
}
51545139
}
51555140

51565141
#[pymethods]
51575142
impl Int64Array {
51585143
#[new]
51595144
#[pyo3(signature = (elements=None))]
5160-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5161-
Ok((
5162-
Int64Array {},
5163-
FSharpArray::new(py, elements, Some("Int64"))?,
5164-
))
5145+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5146+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Int64"))?).add_subclass(Int64Array {}))
51655147
}
51665148
}
51675149

51685150
#[pymethods]
51695151
impl UInt64Array {
51705152
#[new]
51715153
#[pyo3(signature = (elements=None))]
5172-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5173-
Ok((
5174-
UInt64Array {},
5175-
FSharpArray::new(py, elements, Some("UInt64"))?,
5176-
))
5154+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5155+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("UInt64"))?).add_subclass(UInt64Array {}))
51775156
}
51785157
}
51795158

51805159
#[pymethods]
51815160
impl Float32Array {
51825161
#[new]
51835162
#[pyo3(signature = (elements=None))]
5184-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5185-
Ok((
5186-
Float32Array {},
5187-
FSharpArray::new(py, elements, Some("Float32"))?,
5188-
))
5163+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5164+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Float32"))?).add_subclass(Float32Array {}))
51895165
}
51905166
}
51915167

51925168
#[pymethods]
51935169
impl Float64Array {
51945170
#[new]
51955171
#[pyo3(signature = (elements=None))]
5196-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5197-
Ok((
5198-
Float64Array {},
5199-
FSharpArray::new(py, elements, Some("Float64"))?,
5200-
))
5172+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5173+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Float64"))?).add_subclass(Float64Array {}))
52015174
}
52025175
}
52035176

52045177
#[pymethods]
52055178
impl BoolArray {
52065179
#[new]
52075180
#[pyo3(signature = (elements=None))]
5208-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5209-
Ok((BoolArray {}, FSharpArray::new(py, elements, Some("Bool"))?))
5181+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5182+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Bool"))?).add_subclass(BoolArray {}))
52105183
}
52115184
}
52125185

52135186
#[pymethods]
52145187
impl GenericArray {
52155188
#[new]
52165189
#[pyo3(signature = (elements=None))]
5217-
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<(Self, FSharpArray)> {
5218-
Ok((
5219-
GenericArray {},
5220-
FSharpArray::new(py, elements, Some("generic"))?,
5221-
))
5190+
fn new(py: Python<'_>, elements: Option<&Bound<'_, PyAny>>) -> PyResult<PyClassInitializer<Self>> {
5191+
Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("generic"))?).add_subclass(GenericArray {}))
52225192
}
52235193
}
52245194

0 commit comments

Comments
 (0)