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

contribution: Python Stub File #181

Merged
merged 5 commits into from
Jul 9, 2024
Merged

Conversation

iguessitsjeff
Copy link
Contributor

PR adds a stub file to the Python Binding source code in order to give a more clear description when implementing using the Python Package.

Implemented based on Pyo3 Documentation

Vscode Before

Before

Vscode After

After

@gorules gorules deleted a comment from stefan-steadfast Jun 21, 2024
@gorules gorules deleted a comment from stefan-gorules Jun 21, 2024
@stefan-gorules
Copy link
Contributor

This looks great, thanks for contributing. @iguessitsjeff is it enough to simply merge and Pyo3/Maturin will take care of the rest?

@iguessitsjeff
Copy link
Contributor Author

This looks great, thanks for contributing. @iguessitsjeff is it enough to simply merge and Pyo3/Maturin will take care of the rest?

@stefan-gorules Yes, that is all taken care of by Pyo3/Maturin. One thing that I wanted to verify is the expected return values of some of the functions, for example the evaluate functions:
https://github.com/gorules/zen/blob/master/bindings/python/src/engine.rs#L101-L102

It looks like it can return different values other than a python dictionary. Can someone help to list all the expected return values and I can convert the return value into a Union type.

@stefan-gorules
Copy link
Contributor

Hi @iguessitsjeff, this has been held up slightly to make room for #185. After it's merged we can take a look at making minor changes to the stub (as we'll now provide async API for evaluation).

I'll try to provide types here in a bit in TypeScript format, as I'm not fully familiar with Python type capabilities. We can then take a look at updating Python types based on that.

Copy link
Contributor

@stefan-gorules stefan-gorules left a comment

Choose a reason for hiding this comment

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

Please also see #185 which adds two new methods:

ZenEngine.async_evaluate()
ZenDecision.async_evaluate()

Here we should return Awaitable[EvaluateResponse]

bindings/python/zen.pyi Outdated Show resolved Hide resolved
bindings/python/zen.pyi Outdated Show resolved Hide resolved
bindings/python/zen.pyi Outdated Show resolved Hide resolved
bindings/python/zen.pyi Outdated Show resolved Hide resolved
@iguessitsjeff
Copy link
Contributor Author

iguessitsjeff commented Jul 9, 2024

Apologies for the delay!
I made the updates based on the comments.

@stefan-gorules The layout of the struct helped, I created a TypedDict class as there is no structs in Python. The TypedDict class allows users to see type hints in the IDE as to what keys are available.

TypedDict

Additionally, added the Async Functions with the Awaitable return type. Validated that the type hints appear as expected when using async.gather.

AsyncGather

And you are able to access the same keys once accessing the index of the gathered results.

AsyncTypedDict

@stefan-gorules stefan-gorules merged commit 15c4384 into gorules:master Jul 9, 2024
7 checks passed
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

3 participants