Repository navigation
Conversation
g-bauer
force-pushed
the
pyo3_0.30
branch
2 times, most recently
from
November 17, 2026 15:35
dd1b7f5 to
92ada06
Compare
- Bump pyo3, numpy and pythonize to 0.30, and quantity and num-dual to 0.16, which support PyO3 0.30. - Add the `experimental-inspect` feature (forwarding to pyo3 and quantity) to embed introspection data for stub generation. - Declare the Python module as an inline `#[pymodule] mod feos`, which is required for introspection. The rayon thread pool setup moves to an argument-less `#[pymodule_init]`, so the module is not marked incomplete and `__all__` is emitted. - Rename `Verbosity::None` to `Verbosity::Silent` in feos-core (and `Verbosity.None` to `Verbosity.Silent` in Python): `None` is not a valid attribute name in Python and produced an invalid stub, and in Rust it is easily confused with `Option::None`. - Remove the hand-written `text_signature`s: they were partly outdated (missing `$self`, defaults) and disagreed with the generated stubs in 60 methods according to mypy's stubtest. Arguments that accept several types: instead of taking `Bound<PyAny>` and parsing it inside the function, the arguments are extracted into Rust types whose `FromPyObject` implementation carries the union of the accepted types as `INPUT_TYPE`. Like the pyclasses, they are named after the corresponding feos type with a `Py` prefix. They are internal: only the union of the accepted types appears in the stubs. - `PyComposition` (renamed from `Compositions`): moles, total moles, molefracs, or a single molefrac; plus `PyStateComposition` for the partial densities accepted by `State`. - `PyTemperatureOrPressure` for phase equilibrium specifications. Arguments that depend on the specification (`tp_init`, `min_tp`, ...) are converted with `PyTemperatureOrPressure::temperature/pressure`. `State.critical_point_binary` now raises a `ValueError` (instead of a `RuntimeError`) for wrong units, like all other functions. - `PyDensityInitialization` (`Literal['vapor', 'liquid'] | SIObject`). - `PyParametersOrGcParameters` for `EquationOfState.pcsaft`. Error messages are unchanged. Arguments that are only parsed in one place (AD parameter names and values, datasets' `eos`, SMILES identifiers) keep `Bound<PyAny>` and are annotated with strings in their signatures. Returns: `EquationOfState.parameters` and `Dataset.evaluate` return numpy arrays of dynamic dimension (`PyArrayDyn`) instead of untyped objects (the conversion is a cast, no copy). They appear as `Incomplete` in the stubs until numpy provides type hints. The `grid` of DFT profiles is `SIObject | list[SIObject]` and `ThreePhaseEquilibrium` is exported, so `heteroazeotrope` is typed. numpy 0.30 does not provide type hints, so numpy arrays appear as `Incomplete` (i.e. `Any`) in the stubs. The 21 `Any` are pythonize/JSON outputs, user-defined Python models and the AD parameter values. pyright and mypy's stubtest report no errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prehner
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates PyO3 to 0.30 and uses its
experimental-inspectfeature to generate type stubs (.pyi) for thefeosPython package automatically.Dependencies
pyo3,numpyandpythonize0.30;quantityandnum-dual0.16 (all released versions, no patches).py-feosfeatureexperimental-inspect(forwards topyo3andquantity) that embeds the introspection data used for stub generation.API changes
Verbosity::Noneis renamed toVerbosity::Silentin feos-core, andVerbosity.NonetoVerbosity.Silentin Python:Noneis not a valid attribute name in Python (it produced an invalid stub) and is easily confused withOption::Nonein Rust. This is a breaking change for Rust users as well.State.critical_point_binaryraises aValueErrorinstead of aRuntimeErrorfor wrong units, like all other functions that accept a temperature or a pressure.ThreePhaseEquilibriumis exported, soPhaseEquilibrium.heteroazeotropeis typed.EquationOfState.parametersandDataset.evaluatereturn numpy arrays of dynamic dimension instead of untyped objects (a cast, no copy). They are typed in Rust, but appear asIncompletein the stubs until numpy provides type hints.Internal changes
The Python module is declared as an inline
#[pymodule] mod feos(required for introspection). The rayon thread pool setup moves to an argument-less#[pymodule_init].The hand-written
text_signatures are removed; they were partly outdated and disagreed with the generated signatures in 60 methods according to mypy's stubtest.Arguments that accept several types are now extracted into Rust types whose
FromPyObjectimplementation carries the type hint, instead of takingBound<PyAny>and parsing it in the function body. Like the pyclasses, they are named after the corresponding feos type with aPyprefix; they are internal, only the union of the accepted types appears in the stubs:PyComposition(renamed fromCompositions, +PyStateCompositionfor the partial densities accepted byState)PyTemperatureOrPressure; arguments that depend on the specification (tp_init,min_tp, ...) are converted with.temperature()/.pressure()PyDensityInitialization(Literal['vapor', 'liquid'] | SIObject)PyParametersOrGcParameters(inparameter, so other models can reuse it)Error messages are unchanged. Arguments that are parsed in a single place (AD parameter names/values,
Dataset.evaluate'seos, SMILES identifiers) keepBound<PyAny>and get string annotations in theirsignature.Generating the stubs
Notes
numpy0.30 has noexperimental-inspectsupport, so numpy arrays appear asIncomplete(i.e.Any) in the stubs for now.signatureare copied verbatim into the stub, without imports. They can only use builtins and names defined in the stub (e.g.list[str]instead ofSequence[str]).Testing
cargo clippy -p py_feoswithout warnings forwheel,emscripten_wheel,pcsaft,epcsaft,gc_pcsaft,adanddft, each with and withoutexperimental-inspect.cargo test --workspace --all-features(excludingpy_feos): all tests pass.tp_init, critical points, phase diagrams, DFT interfaces, AD derivatives, datasets, GC parameters from SMILES), including the error messages for invalid inputs.--ignore-missing-stub) report no errors.🤖 Generated with Claude Code