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

Parse signature with default value as python default value #88

Closed
wants to merge 2 commits into from

Conversation

Xinihiko
Copy link

@Xinihiko Xinihiko commented Oct 6, 2024

Hi, I have a problem in the generated .pyi results, where it wouldn't show the default value and making the Option<...>
Thus I have added the ability for creating below snippet from the

lib.rs

#[gen_stub_pyfunction]
#[pyfunction(signature=(x=0, y=0))]
fn add_two_number(x: i32, y: i32) -> i32 {...}

#[gen_stub_pyfunction]
#[pyfunction(signature=(numbers, precision=None))]
fn calculate_average(numbers: Vec<f64>, precision: Option<usize>) -> f64 {...}

pyi

def add_two_number(x:int = 0, y:int = 0) -> int:
    ...

def calculate_average(numbers:typing.Sequence[float], precision:typing.Optional[int] = None) -> float:
    ...

which previously was (in the python side we couldn't see the default value)

def add_two_number(x:int = ..., y:int = ...) -> int:
    ...

def calculate_average(numbers:typing.Sequence[float], precision:typing.Optional[int] = ...) -> float:
    ...

helper

(function) def add_two_number(
    x: int = 0,
    y: int = 0
) -> int

(function) def calculate_average(
    numbers: Sequence[float],
    precision: int | None = None
) -> float

I think some of this is caused by the changes made in the pyo3 which changes the Option<..> not to have default value of None
I would hope this could help the autocomplete in the python side.

If there is anything not fit your code structure or any changes need to be made, please let me know.
Thank you in advance

@konn
Copy link
Collaborator

konn commented Jan 17, 2025

Sorry for very late response. I think this is subsumed and addressed in #135 in more robust way. Thank you for your PR and very sorry for our late response 🙇

@konn konn closed this Jan 17, 2025
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.

2 participants