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

use type hints & mypy #50

Open
petri opened this issue Dec 5, 2018 · 5 comments
Open

use type hints & mypy #50

petri opened this issue Dec 5, 2018 · 5 comments

Comments

@petri
Copy link
Member

petri commented Dec 5, 2018

There's a lot of byte & string handling and so on that are easy to get wrong accidentally. Having some type hints and mypy checking them as part of tests would help catch errors & increase code quality.

@jrideout
Copy link
Collaborator

jrideout commented Dec 5, 2018

👍 I actually tried to get this going a week or so a go. I struggled with the difference in types between py2 and py3. I think if we used the future shims consistently, we could get it to work. Unfortunately we are limited to using comment based type hints to maintain support for py2 and early py3 versions rather than the annotation style. And .pyi files cannot be used to validate the files they shadow, which prevents that option.

FYI we are using this in our local typeshed:

# tnefparse/tnef.pyi

from typing import Union

class TNEF:
    htmlbody: Union[str, bytes, None]
    def __init__(self, data: bytes, do_checksum: bool = True): ...

@jrideout
Copy link
Collaborator

I have a typed version locally that was created with https://github.com/dropbox/pyannotate while running the tests. It gets us a lot of the way there. I should have some time in the next few weeks to come back to this, but if anyone else wants to try feel free. I do suggest the pyannotate approach.

@jugmac00
Copy link
Collaborator

@jrideout Is this still something you would like to do?

Otherwise I'd like to type annotate the project.

Either way, thanks a lot for the hint about pyannotate - works like a charm.

@jrideout
Copy link
Collaborator

@jugmac00 Please go-ahead, I'm not actively working on the typing

@jugmac00
Copy link
Collaborator

Currently, I have not much spare time, but I am looking forward to type this project - I will learn a lot, I guess :-)

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