tnefparse icon indicating copy to clipboard operation
tnefparse copied to clipboard

use type hints & mypy

Open petri opened this issue 6 years ago • 5 comments

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.

petri avatar Dec 05 '18 08:12 petri

👍 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 avatar Dec 05 '18 15:12 jrideout

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.

jrideout avatar Dec 11 '18 22:12 jrideout

@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.

jugmac00 avatar Nov 24 '20 21:11 jugmac00

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

jrideout avatar Jan 20 '21 22:01 jrideout

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

jugmac00 avatar Jan 22 '21 13:01 jugmac00