rigetti / rigetti/rigetti-pyo3

py_function_sync_async should work with sync functions that return a future

Open
#59 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
11
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Opentelemetry context propagation in the QCS SDK broke when py_function_sync_async migrated from QCS SDK to this repository. The missing bit is the with_current_context and corresponding (use opentelemetry::trace::FutureExt;):

 macro_rules! py_function_sync_async {
     (
         $(#[$meta: meta])+
         async fn $name: ident($($(#[$arg_meta: meta])*$arg: ident : $kind: ty),* $(,)?) $(-> $ret: ty)? $body: block
     ) => {
         async fn $name($($arg: $kind,)*) $(-> $ret)? {
             $body
         }
 
         ::paste::paste! {
         $(#[$meta])+
         #[allow(clippy::too_many_arguments)]
         #[pyo3(name = $name "")]
         pub fn [< py_ $name >](py: ::pyo3::Python<'_> $(, $(#[$arg_meta])*$arg: $kind)*) $(-> $ret)? {
             use opentelemetry::trace::FutureExt;
             $crate::py_sync::py_sync!(py, $name($($arg),*).with_current_context())
         }
 
         $(#[$meta])+
         #[pyo3(name = $name "_async")]
         #[allow(clippy::too_many_arguments)]
         pub fn [< py_ $name _async >](py: ::pyo3::Python<'_> $(, $(#[$arg_meta])*$arg: $kind)*) -> ::pyo3::PyResult<&::pyo3::PyAny> {
             use opentelemetry::trace::FutureExt;
             $crate::py_sync::py_async!(py, $name($($arg),*).with_current_context())
         }
         }
     };
 }

To avoid introducing anything Opentelemetry in this repository, we should support this macro matching on a sync function that returns a future.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the py_function_sync_async macro and the py_sync and py_async entry points it invokes. Check how the macro currently matches async functions, then verify that it also accepts sync functions returning a future without adding an Opentelemetry dependency; existing macro tests, if present, should cover the new form.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.