ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

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

Closed nikolas-claussen closed 1 year ago

nikolas-claussen commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thanks a lot!

ramonhagenaars commented 1 year ago

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

nikolas-claussen commented 1 year ago

Hello Ramon,

Thank you so much! Works exactly as I hoped now.

Nikolas

On Mon, Feb 20, 2023 at 2:01 PM Ramon Hagenaars @.***> wrote:

With v2.5.0 https://github.com/ramonhagenaars/nptyping/releases/tag/v2.5.0 this issue should be resolved. Please let me know if you encounter any problems still.

— Reply to this email directly, view it on GitHub https://github.com/ramonhagenaars/nptyping/issues/99#issuecomment-1437597379, or unsubscribe https://github.com/notifications/unsubscribe-auth/APUTVVL337QT57BJ4GWL4JDWYPSTZANCNFSM6AAAAAAS754S6U . You are receiving this because you were mentioned.Message ID: @.***>