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

Add support for python type hints in python package #309

Open
PaulOxxx1 opened this issue May 22, 2023 · 6 comments
Open

Add support for python type hints in python package #309

PaulOxxx1 opened this issue May 22, 2023 · 6 comments
Labels
enhancement New feature or request WIP

Comments

@PaulOxxx1
Copy link

Hello everyone 😄,

I would like to ask whether support for python typings could be added to the library, after the recent release of lanelet2 on PyPI.

This would enable static type checking in python (i.e. using mypy), intellisense features, and better feature discoverability in general (since functions will be suggested in the autocomplete UI in code editors).

This section on the mypy site explains how to publish type information for an existing PyPI package (for package maintainers). This is also related to the official PEP 561 - Distributing and Packaging Type Information.

I am not very familiar with Boost.Python, or how the C bindings work for lanelet2, so I am unsure how one would implement the typing support in a way that requires little maintenance (i.e. so that type stub files are auto-generated, much like the python code is itself auto-generated anyway...).

One possible, but very manual solution is to create the .pyi files manually, containing the public interface of the library ... and I have started doing this a little bit for a personal project, so I could contribute something to this, but it is clear that these .pyi files would have to be updated with any interface change of the package ... which would presumably not be too hard, but one extra step.

Please also see the python/typeshed repo for further reference. This repo is a collection of typing files for popular third-party packages which do not have typing support themselves, they are usually contributed by users of the libraries. The typing files for lanelet2 could also be added here ... however, the repo maintainers state as a requirement that "the third-party package needs to support any Python version supported by typeshed" ... which would be Python 3.7 and up, which lanelet2 does not support.

Anyways, perhaps this is something you would consider for future versions of the lanelet2 python package.

@PaulOxxx1
Copy link
Author

PaulOxxx1 commented May 22, 2023

It would also be possible to publish the typing information as a "stub-only" package separately, like types-lanelet2, if this is more suitable.

@poggenhans
Copy link
Contributor

Well its for sure possible to add support and package the .pyi files along with the rest. Are you interested in contributing them? Its unlikely that we will find the time to do them ourselves in the near future. I think the extra effort of maintaining them is doable, the interfaces don't change so frequently.

There are tools in mypy that can autogenerate them, but they perform extremely poorly on boost::python generated bindings. For lanelet2, not a single function signature was deduced correctly when I tested it.

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no activity. Is this issue still work in progress? If yes, mark it as "WIP" or comment, otherwise it will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 23, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2023
@muety
Copy link

muety commented Oct 9, 2023

Would love to have Python type hints included!

@poggenhans poggenhans removed the Stale label Oct 10, 2023
@poggenhans poggenhans reopened this Oct 10, 2023
@poggenhans poggenhans added the enhancement New feature or request label Oct 10, 2023
@poggenhans
Copy link
Contributor

This shouldn't have been closed. This issue is waiting for a knight in shining armor to resolve it.

@immel-f immel-f added the WIP label Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request WIP
Projects
None yet
Development

No branches or pull requests

4 participants