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 type hints #1510

Open
webknjaz opened this issue Oct 2, 2016 · 4 comments
Open

Add type hints #1510

webknjaz opened this issue Oct 2, 2016 · 4 comments

Comments

@webknjaz
Copy link
Member

webknjaz commented Oct 2, 2016

Hi,

I think for such project as a framework it's a must to incorporate all available tools helping to keep the codebase healthy.
Today I'm thinking about using type hinting natively available in Python 3.5/3.6 (PEP-3107/PEP-526/PEP-484) and available for old Python versions via various backports/mypy etc.

@jaraco do you think we could do this?

@jaraco
Copy link
Member

jaraco commented Oct 2, 2016

Seems reasonable, though Python 2 compatibility might be tough. I haven't used tools that leverage type annotations myself, so I'm not quite sure what to expect. As long as the implementation doesn't raise the bar too much for new contributors, it should be worthwhile.

@jaraco jaraco removed their assignment Oct 2, 2016
@webknjaz
Copy link
Member Author

webknjaz commented Oct 2, 2016

Well, current Python 2 implementations use either decorators, or comments for annotations.

@davetapley
Copy link

bump

I presume this is less intimidating now since Python 2 support was dropped in v18.0.0?

Also want to call out progress over here:

Happy to help if we want to try and get this done 😁

@webknjaz could you maybe change the issue title to "Add type hints"? 🙏🏻

@webknjaz webknjaz changed the title Mature static linting with type hints Add type hints Jan 25, 2024
@webknjaz
Copy link
Member Author

I changed the issue title. Although, I think the old one was just fine...

In case of Cheroot, we've gone the way of type stubs which are *.pyi files, as opposed to backing the syntax into the Python files. I felt like that would help us do backports in Python 2-compatible manner.

But realistically, Python 2 has been dead for 4 years so we shouldn't need to care about it anymore.

@davetapley feel free to start with adding MyPy to .pre-commit-config.yaml and mypy.ini. Reproduce what's done in Cheroot and aio-libs/frozenlist, aio-libs/multidict, aio-libs/yarl — these are the most recent examples of my work. Some are more detailed than others (for example, frozenlist even has typing stubs coverage reported to Codecov!).

Please, make small PRs since it's easier to review and comprehend tiny bits of text/diffs. Also, don't turn all toggles on together in one PR. Incremental changes work best.

I'll be judging the acceptance of PRs by whether the pre-commit.ci check is green, since that's where MyPy needs to be integrated.

As a future bonus, we may consider running other type checkers to cover more corner cases.

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

3 participants