Skip to content

Commit 0153ed2

Browse files
committed
Add from_py_object to pyclass attrs
Add the from_py_object flag to many #[cfg_attr(feature = "python", pyclass(...))] annotations across the codebase to enable FromPyObject conversions for pyo3 Python interop. Changes affect attribute.rs, datamodel.rs, exporters.rs, markdown/frontmatter.rs, markdown/position.rs, object.rs, option.rs, and xmltype.rs. No behavioral logic was changed; this only augments Python FFI annotations to allow constructing these Rust types directly from Python objects.
1 parent 5e9f226 commit 0153ed2

8 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/attribute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use tsify_next::Tsify;
3939

4040
/// Represents an attribute with various properties and options.
4141
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
42-
#[cfg_attr(feature = "python", pyclass(get_all))]
42+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
4343
#[cfg_attr(feature = "wasm", derive(Tsify))]
4444
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
4545
pub struct Attribute {
@@ -274,7 +274,7 @@ impl Attribute {
274274
}
275275

276276
#[derive(Debug, Clone)]
277-
#[cfg_attr(feature = "python", pyclass)]
277+
#[cfg_attr(feature = "python", pyclass(from_py_object))]
278278
#[cfg_attr(feature = "wasm", derive(Tsify))]
279279
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
280280
pub enum DataType {

src/datamodel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const MERGE_IGNORE_TYPES: &[&str] = &["UnitDefinition", "BaseUnit", "UnitType"];
7474
// * `json_schema_all` - Generate JSON schemas for all objects in the data model
7575
// * `internal_schema` - Generate an internal schema from the data model
7676
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
77-
#[cfg_attr(feature = "python", pyclass(get_all))]
77+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
7878
#[cfg_attr(feature = "wasm", derive(Tsify))]
7979
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
8080
pub struct DataModel {

src/exporters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ lazy_static! {
114114

115115
/// Enumeration of available templates.
116116
#[derive(Debug, ValueEnum, Clone, PartialEq)]
117-
#[cfg_attr(feature = "python", pyclass(eq, eq_int))]
117+
#[cfg_attr(feature = "python", pyclass(eq, eq_int, from_py_object))]
118118
#[cfg_attr(feature = "wasm", wasm_bindgen)]
119119
pub enum Templates {
120120
/// XML Schema

src/markdown/frontmatter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::prelude::DataModel;
3636

3737
/// Represents the front matter data of a markdown file.
3838
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
39-
#[cfg_attr(feature = "python", pyclass(get_all))]
39+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
4040
#[cfg_attr(feature = "wasm", derive(Tsify))]
4141
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
4242
pub struct FrontMatter {
@@ -115,7 +115,7 @@ impl FrontMatter {
115115
}
116116

117117
#[derive(Debug, Serialize, Clone, PartialEq)]
118-
#[cfg_attr(feature = "python", pyclass(get_all))]
118+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
119119
#[cfg_attr(feature = "wasm", derive(Tsify))]
120120
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
121121
/// Represents different types of model imports.

src/markdown/position.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tsify_next::Tsify;
3030
use pyo3::prelude::*;
3131

3232
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
33-
#[cfg_attr(feature = "python", pyclass(get_all))]
33+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
3434
#[cfg_attr(feature = "wasm", derive(Tsify))]
3535
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
3636
pub struct Position {
@@ -46,7 +46,7 @@ impl PartialOrd for Position {
4646
}
4747

4848
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
49-
#[cfg_attr(feature = "python", pyclass(get_all))]
49+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
5050
#[cfg_attr(feature = "wasm", derive(Tsify))]
5151
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
5252
pub struct PositionRange {

src/object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use tsify_next::Tsify;
3636

3737
#[skip_serializing_none]
3838
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
39-
#[cfg_attr(feature = "python", pyclass(get_all))]
39+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
4040
#[cfg_attr(feature = "wasm", derive(Tsify))]
4141
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
4242
/// Represents an object with a name, attributes, docstring, and an optional term.
@@ -204,7 +204,7 @@ impl Hash for Object {
204204
}
205205

206206
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
207-
#[cfg_attr(feature = "python", pyclass(get_all))]
207+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
208208
#[cfg_attr(feature = "wasm", derive(Tsify))]
209209
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
210210
/// Represents an enumeration with a name and mappings.

src/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use tsify_next::Tsify;
4444
/// - Custom options via the `Other` variant
4545
///
4646
#[derive(Debug, Clone, PartialEq, EnumString, Display)]
47-
#[cfg_attr(feature = "python", pyclass(get_all))]
47+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
4848
#[cfg_attr(feature = "wasm", derive(Tsify))]
4949
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
5050
#[derive(Serialize, Deserialize)]
@@ -211,7 +211,7 @@ impl AttrOption {
211211
/// which is useful for serialization/deserialization and when working
212212
/// with untyped data.
213213
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
214-
#[cfg_attr(feature = "python", pyclass(get_all))]
214+
#[cfg_attr(feature = "python", pyclass(get_all, from_py_object))]
215215
#[cfg_attr(feature = "wasm", derive(Tsify))]
216216
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
217217
pub struct RawOption {

src/xmltype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tsify_next::Tsify;
3232

3333
/// Represents an XML type, either an attribute or an element.
3434
#[derive(Debug, PartialEq, Clone)]
35-
#[cfg_attr(feature = "python", pyclass)]
35+
#[cfg_attr(feature = "python", pyclass(from_py_object))]
3636
#[cfg_attr(feature = "wasm", derive(Tsify))]
3737
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi))]
3838
pub enum XMLType {

0 commit comments

Comments
 (0)