mirror of
https://github.com/qdrant/qdrant.git
synced 2026-08-05 01:20:53 -05:00
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:
12
lib/edge/python/codegen/src/lib.rs
Normal file
12
lib/edge/python/codegen/src/lib.rs
Normal 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(),
|
||||
}
|
||||
}
|
||||
34
lib/edge/python/codegen/src/pyclass_repr.rs
Normal file
34
lib/edge/python/codegen/src/pyclass_repr.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user