flatten-dict icon indicating copy to clipboard operation
flatten-dict copied to clipboard

add typehints with mypy

Open rwadman opened this issue 2 years ago • 5 comments

Hello! We're using flatten-dict in a typed context at work, so I created some stubs for it the other day. Felt like it could be nice to share them with you, but I think it's much easier to maintain typehints if they're written inline with the code, so I spent some time this weekend writing that up.

Had to upgrade black to avoid some broken import, and did my best to configure static type checking with mypy.

Don't know if you're interested at all, so feel free to ignore, but here you have it :)

rwadman avatar Apr 10 '22 16:04 rwadman

Noticed now that I forgot to add the type checking to CI, will see if I can figure that out...

rwadman avatar Apr 10 '22 16:04 rwadman

Thanks. I'm very interested in mypy, but didn't have time to learn it. I will spend some time understanding this PR.

ianlini avatar Apr 12 '22 16:04 ianlini

Are you using the comments because we are still supporting Python 2.7? I think it's time to remove it so that we can use the type annotation.

ianlini avatar Apr 12 '22 17:04 ianlini

Nice! Yes, the type comments are there to support python < 3.5, which (I think) is the first version with support for proper annotations.

Which python versions we should support is your call I feel. If your certain about dropping 2.7 (and probably also anything else before 3.5) I could update the PR to move away from the type comment style. It would also simplify the tox setup a bit since we would then be able to typecheck for each version of python with the tox environment for that version (to typecheck for python 2.7 you have to run mypy in python >3.5).

rwadman avatar Apr 13 '22 19:04 rwadman

Yes, please drop Python 2.7.

ianlini avatar Apr 14 '22 02:04 ianlini