Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PyO3 #244

Merged
merged 6 commits into from May 16, 2023
Merged

Update PyO3 #244

merged 6 commits into from May 16, 2023

Conversation

whoahbot
Copy link
Contributor

Updates PyO3 to 0.18.3

There may be a better way to unpack args within add_pymethods! that removes the need to write out both args and signature, but my macro skills are sadly not up to the task.

Copy link
Contributor

@Psykopear Psykopear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a difference between signature and args. args's default (what's after =>) is not the default value used in the python constructor, but just a default value for a specific type to be used in __getnewargs__, which isn't the same thing. We still need both, for example if any argument is not optional, we don't want to add a default in signature but still need it in args. So we need signature to setup py_new args between positional, optional kwarg and mandatory kwarg, see the comments on the PR. We could change the macro syntax to get all the info in one "field", but I'm not sure we'll gain much.

Another place where we can make use of signature and autogenerated text_signature is all the public methods in Dataflow struct (like input, map ecc.). Since all the arguments are positional, we can use signature instead of text_signature everywhere there.

One more thing, given this PR: PyO3/pyo3#2939 we can also add default-features = false to our own dependency on chrono, so we can get rid of the time dependency too, I tried it locally and everything seems to work.

Also, I noticed the signatures for the tracing configs are not quite right (sampling_ratio should default to 1.0, and it should be an f64 rather than an Option<f64>), but that's not related to this PR, so maybe I can make a separate PR with the fix after this is merged.

src/run.rs Outdated
Comment on lines 103 to 105
#[pyfunction(flow, "*", epoch_interval = "None", recovery_config = "None")]
#[pyfunction]
#[pyo3(text_signature = "(flow, *, epoch_interval, recovery_config)")]
pub(crate) fn run_main(
Copy link
Contributor

@Psykopear Psykopear May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text_signature here implies that epoch_interval and recovery_config are mandatory kwargs, while they are optional kwargs. Also, since text_signature doesn't generate signature, while the reverse is true, if we want to show the default as "None" rather than "...", we need to use both ( https://pyo3.rs/v0.18.3/function/signature#overriding-the-generated-signature ):

#[pyo3(
    signature = (flow, *, epoch_interval = None, recovery_config = None),
    text_signature = "(flow, *, epoch_interval = None, recovery_config = None)"
)]

src/run.rs Outdated
Comment on lines 204 to 207
#[pyo3(
signature = (flow, addresses, proc_id, *, epoch_interval = None, recovery_config = None, worker_count_per_proc = 1),
text_signature = "(flow, addresses, proc_id, *, epoch_interval, recovery_config, worker_count_per_proc)"
)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, text_signature should include the default value:

#[pyo3(
    signature = (flow, addresses, proc_id, *, epoch_interval = None, recovery_config = None, worker_count_per_proc = 1),
    text_signature = "(flow, addresses, proc_id, *, epoch_interval = None, recovery_config = None, worker_count_per_proc = 1)"
)]

src/run.rs Outdated
Comment on lines 318 to 330
#[pyfunction]
#[pyo3(
signature = (
flow,
*,
processes = 1,
workers_per_process = 1,
process_id = None,
addresses = None,
epoch_interval = None,
recovery_config = None
)
)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we should include the text_signature:

#[pyo3(
    signature=(flow, *, processes=1, workers_per_process=1, process_id=None, addresses=None, epoch_interval=None, recovery_config=None),
    text_signature="(flow, *, processes=1, workers_per_process=1, process_id=None, addresses=None, epoch_interval=None, recovery_config=None)"
)]

@@ -52,7 +52,7 @@ pub(crate) struct SlidingWindow {
add_pymethods!(
SlidingWindow,
parent: WindowConfig,
py_args: (length, offset, align_to),
signature: (length=Duration::zero(), offset=Duration::zero(), align_to=DateTime::<Utc>::MIN_UTC),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not right, signature should only have default values if the argument is optional, and this is not the case here, so signature should still be (length, offset, align_to)

@@ -35,7 +35,7 @@ impl WindowBuilder for SessionWindow {
add_pymethods!(
SessionWindow,
parent: WindowConfig,
py_args: (gap),
signature: (gap=Duration::zero()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since gap is mandatory, we should not add a default value in the signature here:
signature: (gap)

@@ -68,7 +68,7 @@ impl ClockBuilder<TdPyAny> for EventClockConfig {
add_pymethods!(
EventClockConfig,
parent: ClockConfig,
py_args: (dt_getter, wait_for_system_duration),
signature: (dt_getter, wait_for_system_duration=Duration::zero()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait_for_system_duration is not optional in our current api, so we shouldn't add a default value here:
signature: (dt_getter, wait_for_system_duration)

- Fixes issues with using `signature` incorrectly.
- Use `default-features = false` with chrono to avoid time dependency.
- Fixes signatures for the tracing configs.
- Moves `python-source` from Cargo.lock to pyproject.toml for Maturin compatibility
- Don't install dill
@whoahbot whoahbot requested a review from Psykopear May 15, 2023 23:22
Copy link
Contributor

@Psykopear Psykopear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@whoahbot whoahbot merged commit 72ef095 into main May 16, 2023
21 checks passed
@whoahbot whoahbot deleted the update_pyo3 branch May 16, 2023 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants