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

How to get better __repr__ / autogenerated docstring for functions with type hints? #99

Closed
nikolas-claussen opened this issue Dec 15, 2022 · 4 comments · Fixed by #101
Closed

Comments

@nikolas-claussen
Copy link

Hi there,

Would it be possible to get the type hints in a function definition automatically integrated into the function's docstring and/or string representation? Using the example from the github page, the function
def plan_route(locations: NDArray[Shape["[from, to], [x, y]"], Float]) -> NDArray[Shape["* stops, [x, y]"], Float]: pass
currently has the following help string:
plan_route(locations: nptyping.base_meta_classes.NDArray) -> nptyping.base_meta_classes.NDArray
which is not very helpful. The desired behavior would be something like:
plan_route(locations: NDArray[Shape["[from, to], [x, y]"], Float]) -> NDArray[Shape["* stops, [x, y]"], Float]

Or is this already supported?

@ramonhagenaars
Copy link
Owner

Hi @nikolas-claussen ,

I looked into this and it turns out that the help text does not use __str__ or __repr__. There is no trivial way to control what is shown in the help text.

However, with some dirty hacks special tricks, I managed to make the help text more helpful. Look for it in release 2.5.0.

@nikolas-claussen
Copy link
Author

Thanks a lot!

@ramonhagenaars
Copy link
Owner

With v2.5.0 this issue should be resolved. Please let me know if you encounter any problems still.

@nikolas-claussen
Copy link
Author

nikolas-claussen commented Apr 5, 2023 via email

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 a pull request may close this issue.

2 participants