Skip to content

chore(python): use PyClassInitializer for typed array subclasses#4666

Merged
dbrattli merged 1 commit into
mainfrom
fix/pyo3-pyclassinitializer
Jun 16, 2026
Merged

chore(python): use PyClassInitializer for typed array subclasses#4666
dbrattli merged 1 commit into
mainfrom
fix/pyo3-pyclassinitializer

Conversation

@dbrattli

Copy link
Copy Markdown
Collaborator

Summary

The fable-library-core Rust extension emitted 12 deprecation warnings when compiling against pyo3 0.29:

warning: use of deprecated method `pyo3::internal::pyclass_init::TpNewTupleResolver::<S, (S, B)>::resolve`: Tuple syntax for super class initialization is phased out. Use `PyClassInitializer` instead.

This migrates all 12 typed-array subclass constructors in src/fable-library-py/src/array.rs from the deprecated (Self, FSharpArray) tuple return to PyClassInitializer.

Before:

fn new(...) -> PyResult<(Self, FSharpArray)> {
    Ok((Int8Array {}, FSharpArray::new(py, elements, Some("Int8"))?))
}

After:

fn new(...) -> PyResult<PyClassInitializer<Self>> {
    Ok(PyClassInitializer::from(FSharpArray::new(py, elements, Some("Int8"))?).add_subclass(Int8Array {}))
}

Applied to Int8Array, UInt8Array, Int16Array, UInt16Array, Int32Array, UInt32Array, Int64Array, UInt64Array, Float32Array, Float64Array, BoolArray, and GenericArray.

Test plan

  • cargo build now finishes with zero warnings (previously 12).
  • PyClassInitializer was already in scope via pyo3::prelude::*; no import change needed.

🤖 Generated with Claude Code

Migrate the 12 typed-array subclass constructors in array.rs from PyO3's
deprecated tuple syntax for super class initialization to
PyClassInitializer, silencing the deprecation warnings emitted by pyo3
0.29.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli dbrattli merged commit 7f88ca7 into main Jun 16, 2026
32 checks passed
@dbrattli dbrattli deleted the fix/pyo3-pyclassinitializer branch June 16, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant