question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add type hints in python codebase

See original GitHub issue

🚀 Feature Proposal

Type hints in Python are specified by PEP 484 and are of a great help when developing, thus proposing to add them to Python codebase. Would this be an option if I volunteer to (gradually) add them, assuming the types are validated in the CI by a checker tool like mypy so the types are validated on each pull request?

I have noticed rudimentary type hints already exist here and there, for example

https://github.com/SeleniumHQ/selenium/blob/e9c738de8a587dc6bc86b55949c57b8574ec68bb/py/selenium/webdriver/remote/webdriver.py#L263

indicates that WebDriver().name is a string. This offers better code completions in IDEs.

I have searched for similar issues, but it seems like this wasn’t discussed yet (at least not on Github). As far as I can see, the only issue mentioning type hints is #1917; however, type stubs were removed since then.

Another alternative would be maintaining a third-party stub package (as specified in PEP 561). However, I don’t want to start a third-party package if you are willing to keep the type hints along with the code (which is a much better option), or planning to add them already.

Motivation

Better code completion in IDEs is surely something the end users will appreciate. Another advantage is that type hints often intercept bugs, thus making the code more robust.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
AutomatedTestercommented, May 17, 2021

I am all for this! Feel free to start adding PRs and then tagging me for review.

2reactions
AutomatedTestercommented, Feb 24, 2022

landed in e8e9389f6b793a51e9cf5989eab7b55982ccbf6d

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploring Python Type Hints - Towards Data Science
In this post, I want to introduce Python type hints and discuss why I think they could be a really powerful addition to...
Read more >
typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar...
Read more >
Python Type Hints: How to Gradually Add Types for Third ...
One place you can apply graduality with Mypy is in the type hints for third party packages. The default course of action is...
Read more >
Type hinting and annotations - Python for you and me
You can learn more about types from PEP 484. The typing module has detailed explanation and more examples about how to add type...
Read more >
Get started with Python type hints | InfoWorld
Get started with Python type hints. Learn how to use Python's optional type hinting syntax for creating cleaner and more useful code bases....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found