Implement __repr__ for Qdrant Edge types (#7695)

* Refactor `PyUpdateOperation` constructors

* Add default parameters to `PyVectorDataConfig::new`

* Add `Repr` trait and `WriteExt` helper

* Implement `__repr__` for config types

* fixup! Implement `__repr__` for config types

Use `Copy` instead of `Clone`

* fixup! Implement `__repr__` for config types

Add basic test

* Implement `__repr__` for `PyPointId`

* Implement `__repr__` for `PyVector`

* Implement `__repr__` for `PyVectorInternal`

* Implement `__repr__` for `PyPayload`

* Implement `__repr__` for `PyValue`

* Implement `__repr__` for `PyPoint`

* Implement `__repr__` for `PyPointVectors`

* Implement `__repr__` for `PyRecord`

* Move `PyScoredPoint` into a separate file

* Implement `__repr__` for `PyScoredPoint`

* Cleanup examples

* fixup! Implement `__repr__` for `PyScoredPoint`

* Move `PyOrderValue` into separate file

* Add `PyScoredPoint::order_value`

* Implement `pyclass_repr` proc-macro attribute

* Implement `__repr__` for config types using `pyclass_repr` attribute

* Implement `__repr__` for `PySparseVector` using `pyclass_repr` attribute

* Implement `__repr__` for `PyPoint` using `pyclass_repr` attribute

* Implement `__repr__` for `PyPointVectors` using `pyclass_repr` attribute

* Implement `__repr__` for `PyRecord` using `pyclass_repr` attribute

* Implement `__repr__` for `PyScoredPoint` using `pyclass_repr` attribute

* Minor fixes and cleanups

* fixup! Minor fixes and cleanups

* rollback copy for quantization config

* rollback copy for quantization config

---------

Co-authored-by: generall <andrey@vasnetsov.com>
This commit is contained in:
Roman Titov
2025-12-16 02:17:37 +01:00
committed by GitHub
parent 5b71996247
commit 1bf968bd10
30 changed files with 1154 additions and 317 deletions

View File

@@ -0,0 +1,12 @@
mod pyclass_repr;
#[proc_macro_attribute]
pub fn pyclass_repr(
_attributes: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
match pyclass_repr::pyclass_repr(input.into()) {
Ok(output) => output.into(),
Err(error) => error.to_compile_error().into(),
}
}

View File

@@ -0,0 +1,34 @@
pub fn pyclass_repr(input: proc_macro2::TokenStream) -> syn::Result<proc_macro2::TokenStream> {
let impl_block: syn::ItemImpl = syn::parse2(input)?;
let type_name = &impl_block.self_ty;
let mut fields = Vec::new();
for item in &impl_block.items {
let syn::ImplItem::Fn(func) = item else {
continue;
};
if !func.attrs.iter().any(|attr| attr.path().is_ident("getter")) {
continue;
}
fields.push(&func.sig.ident);
}
let output = quote::quote! {
#impl_block
impl crate::repr::Repr for #type_name {
fn fmt(&self, f: &mut crate::repr::Formatter<'_>) -> std::fmt::Result {
use crate::repr::WriteExt as _;
f.class::<Self>(&[
#( (stringify!(#fields), &self.#fields()) ),*
])
}
}
};
Ok(output)
}