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 Python typings #139

Merged
merged 9 commits into from
Aug 1, 2023
Merged

Update Python typings #139

merged 9 commits into from
Aug 1, 2023

Conversation

piotr-roslaniec
Copy link

@piotr-roslaniec piotr-roslaniec commented Jul 10, 2023

Type of PR:

  • Bugfix

Required reviews:

  • 2

What this does:

  • Fixes some Python typings not matching their runtime definition
  • Adds mypy.stubtest check to CI
  • Runs umbral-pre-python/example/example.py on CI
  • Renames ferveo_py to ferveo module
  • Removes dependency on maturing for releasing
  • Removes maturin.yml CI workflow
  • Minor change to FerveoVariant Python type

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

  • Downstream changes: Update ferveo Python typings nucypher-core#71
  • Removing maturin on the back of these changes
    • maturin built modules are not recognized by mypy.stubtest for some reason
    • Switching to setup compatible with how we release Python packages in rust-umbral and nucypher-core
    • We don't plan maintain ferveo Python package anyway; We'd rather use bindings exposed from nucypher-core
  • MINOR version bump

@piotr-roslaniec piotr-roslaniec changed the title fix: python typings don't match runtime Update Python typings Jul 10, 2023
Base automatically changed from development to main July 10, 2023 10:18
@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2023

Codecov Report

Merging #139 (0e7c561) into main (ffb9b21) will decrease coverage by 0.52%.
The diff coverage is 7.40%.

@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   78.48%   77.96%   -0.52%     
==========================================
  Files          24       23       -1     
  Lines        4954     4979      +25     
==========================================
- Hits         3888     3882       -6     
- Misses       1066     1097      +31     
Impacted Files Coverage Δ
ferveo-python/src/lib.rs 0.00% <0.00%> (-20.00%) ⬇️
ferveo/src/api.rs 89.96% <0.00%> (-1.08%) ⬇️
ferveo/src/bindings_wasm.rs 0.00% <0.00%> (ø)
ferveo/src/bindings_python.rs 51.98% <11.42%> (-1.47%) ⬇️

... and 5 files with indirect coverage changes

@piotr-roslaniec piotr-roslaniec marked this pull request as ready for review July 10, 2023 10:43
ferveo-python/Cargo.toml Show resolved Hide resolved
class DecryptionSharePrecomputed:
@staticmethod
def from_bytes(data: bytes) -> DecryptionSharePrecomputed:
def from_bytes(bytes: bytes) -> DecryptionSharePrecomputed:
Copy link
Member

Choose a reason for hiding this comment

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

I made an identical comment in nucypher/nucypher-core#72, but I'd prefer to avoid name shadowing bytes() throughout this changeset.

Copy link
Author

Choose a reason for hiding this comment

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

I will backport these changes to nucypher-core (similar to any changes that may happen with rust_umbral)

) -> bytes:
...


def combine_decryption_shares_precomputed(
decryption_shares: Sequence[DecryptionSharePrecomputed],
shares: Sequence[DecryptionSharePrecomputed],
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

Comment on lines 133 to 140
(1, FerveoVariant.simple),
(4, FerveoVariant.simple),
(8, FerveoVariant.simple),
(32, FerveoVariant.simple),
(1, FerveoVariant.precomputed),
(4, FerveoVariant.precomputed),
(8, FerveoVariant.precomputed),
(32, FerveoVariant.precomputed),
Copy link
Member

Choose a reason for hiding this comment

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

Let's introduce some odd numbers to this parametrization, after it's supported (now?).

Copy link
Author

Choose a reason for hiding this comment

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

✔️

Copy link
Member

@KPrasch KPrasch left a comment

Choose a reason for hiding this comment

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

👨🏻‍🚀

fn precomputed() -> &'static str {
api::FerveoVariant::Precomputed.as_str()
fn precomputed() -> FerveoVariant {
api::FerveoVariant::Precomputed.into()
Copy link
Member

Choose a reason for hiding this comment

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

🔥 - this seems much better than using strings.

assert FerveoVariant.simple() == "FerveoVariant::Simple"
assert str(FerveoVariant.precomputed) == "FerveoVariant::Precomputed"
assert str(FerveoVariant.simple) == "FerveoVariant::Simple"
assert FerveoVariant.precomputed == FerveoVariant.precomputed
Copy link
Member

Choose a reason for hiding this comment

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

👍

pub fn precomputed() -> String {
api::FerveoVariant::Precomputed.as_str().to_string()
pub fn precomputed() -> FerveoVariant {
FerveoVariant(api::FerveoVariant::Precomputed)
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸

@piotr-roslaniec
Copy link
Author

These changes are confirmed to be working upstream, so I'd be happy to merge this once nucypher/nucypher#3171 is reviewed

class FerveoVariant:
@staticmethod
def simple() -> str: ...
simple: FerveoVariant
Copy link
Member

@derekpierre derekpierre Jul 13, 2023

Choose a reason for hiding this comment

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

One minor nitpick I didn't pick up on earlier (and I know it's annoying), but can these be SIMPLE/PRECOMPUTED or Simple/Precomputed. The lowercase looks a little weird in the Python code 😅

Copy link
Author

Choose a reason for hiding this comment

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

These are class attributes, so I assumed they should be lowercase. I can fix this.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. Admittedly, it's a nitpick so if it is easy to fix/makes sense then great; if not, then you can ignore.

I didn't notice it until I saw it used in the 3171.

@piotr-roslaniec
Copy link
Author

Tested in nucypher/nucypher#3171

@piotr-roslaniec piotr-roslaniec merged commit dc9d81a into main Aug 1, 2023
@piotr-roslaniec piotr-roslaniec deleted the fix-typings branch August 1, 2023 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

4 participants