extruct icon indicating copy to clipboard operation
extruct copied to clipboard

[suggestion] adding type hints?

Open sbdchd opened this issue 3 years ago • 7 comments

I see this package supports python 2.7 so the type hints would have to be the comment variety:

https://web.archive.org/web/20220213164145/https://mypy.readthedocs.io/en/stable/cheat_sheet.html

Essentially:

def add(a, b):
    # type: (int, int) -> int
    return a + b

instead of:

def add(a: int, b: int) -> int:
    return a + b

edit: another option would be some type stub files .pyi

sbdchd avatar Oct 01 '22 20:10 sbdchd

I think dropping python 2.7 support won't be a problem

lopuhin avatar Oct 03 '22 10:10 lopuhin

would you be open to a PR introducing type hints & dropping 2.7 support?

sbdchd avatar Oct 03 '22 22:10 sbdchd

Yes that would be helpful 👍 If you plan to make any code changes while dropping 2.7 support (e.g. clean-up six imports and other stuff required only for python 2.7), then I think it would be better to do so in a separate PR, and then add hints.

Regarding python 3 versions, I think we can definitely drop 3.5 support. In case 3.6 support would be a problem, we can discuss dropping that as well.

lopuhin avatar Oct 05 '22 10:10 lopuhin

Also, any thoughts on adding something like black for auto formatting? makes writing the types a little less cumbersome from the formatting changes

sbdchd avatar Oct 06 '22 22:10 sbdchd

Re black, we use it in a few projects, such as https://github.com/scrapinghub/web-poet/ and https://github.com/scrapinghub/scrapy-poet, and the folks running these projects are happy with the setup (cc @BurnzZ ). Do you have a preferred approach or experience migrating other projects @sbdchd ?

lopuhin avatar Oct 07 '22 06:10 lopuhin

It'd be cool if we also have pre-commit hooks available with isort and flake8 as well. :) Ref: https://github.com/scrapinghub/web-poet/blob/master/.pre-commit-config.yaml

BurnzZ avatar Oct 07 '22 07:10 BurnzZ

yeah basically in my experience adding type hints changes a ton of formatting, so having black helps a bit -- plus I like the look of the output :D

sbdchd avatar Oct 08 '22 02:10 sbdchd