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

Adding type hints to the function signatures #1062

Closed
3 tasks done
Vuizur opened this issue Sep 26, 2023 · 5 comments
Closed
3 tasks done

Adding type hints to the function signatures #1062

Vuizur opened this issue Sep 26, 2023 · 5 comments

Comments

@Vuizur
Copy link

Vuizur commented Sep 26, 2023

Contributing guidelines

  • I understand the contributing guidelines

Documentation

  • My proposal is not addressed by the documentation or examples

Existing issues

  • Nothing similar appears in an existing issue

What problem does your feature proposal solve?

The types of the parameters and the returned data of the functions is already very well documented. Currently the data is in docstrings, which unfortunately IDEs like VS Code cannot use. Putting them additionally directly in the function signatures would have several advantages:

  • Make it easier for users to see what they need to input without having to scroll through the docstrings
  • Enable type checkers to find quickly find errors if the user uses something wrong
  • Enable autocomplete on returned values

What is your proposed solution?

One could simply copy the info out of the docstrings and put it in the function signatures. I think using from __future__ import annotations would be the best choice, as we could use modern constructs from Python 3.10+ and still have a runnable program on Python 3.8.

What alternatives have you considered?

One could also create type stubs, but they would be harder to maintain and get out of date.

Additional context

@gboeing
Copy link
Owner

gboeing commented Oct 6, 2023

@Vuizur thanks for the suggestion. Yes this has been on my radar and I hope to incorporate type annotations into OSMnx v2.0 (aiming for a 2024 release). The current plan is for v2.0 to support Python 3.9+ and drop support for Python 3.8. Reading the 3.9 release notes it looks like we should be able to avoid using from __future__ import annotations, if so.

@gboeing
Copy link
Owner

gboeing commented Jan 2, 2024

Work in progress in the typing branch.

@gboeing
Copy link
Owner

gboeing commented Jan 11, 2024

Proposed resolution in #1107. Comments, feedback, and improvements welcome.

@gboeing gboeing mentioned this issue Jan 11, 2024
6 tasks
@gboeing
Copy link
Owner

gboeing commented Jan 20, 2024

Merged into the v2 branch and targeted for release in 2.0.0.

@gboeing gboeing closed this as completed Jan 20, 2024
@gboeing
Copy link
Owner

gboeing commented May 3, 2024

The first pre-release OSMnx v2 beta has been released. Testers needed! See #1123 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants