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.

Assessment

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

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.

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.

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

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from rigetti/rigetti-pyo3

All issues in rigetti/rigetti-pyo3

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.