-
Notifications
You must be signed in to change notification settings - Fork 52
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
Type hinting #138
Type hinting #138
Conversation
Added support for type hinting for consistency with `sorted` from builtints. This allows Iterables of Custom Objects to be typed.
Support Type Hinting
This will enable typechecking during testing.
I have been wanting to do this for quite some time, but needed the functionality of the IntEnum for backwards-compatibility. Now that Python 3.5 is no longer supported, the IntEnum can be used and the definition of ns is far simpler than it used to be. This plays nice with mypy also, which is the driving change.
Without adding any annotations, make sure mypy is happy.
Very nice! Excited to see typing support being build. |
The compat and __main__ files have had type hints added. The unicode_* files all do not need type hints (because all variables are deducable), same with the ns_enum file.
OK - this *might* have gone a bit overboard, but I have always thought it was hard to keep track of what most of the utility functions are returning and this really helps.
The annotations were so complex that it made the documentation hard to follow.
That was... a lot. There are still errors in the os_sorted tests, but that requires me to rethink some typing decisions in the main code so that will be for a future commit.
Some over-specified types have been made a bit more general.
Codecov Report
@@ Coverage Diff @@
## master #138 +/- ##
==========================================
- Coverage 99.35% 96.57% -2.79%
==========================================
Files 10 10
Lines 466 613 +147
==========================================
+ Hits 463 592 +129
- Misses 3 21 +18
Continue to review full report at Codecov.
|
60b582d
to
92f72c9
Compare
This was missed when 3.5 support was removed.
92f72c9
to
13ef04c
Compare
Huzzah! Before I merge this, I think I want to add type hints to |
This will expose Natsort's types to libraries using it.
Originally I did not realize that it was possible to put the keyword arguments in an overload, so I ended up doing way more overload definitions than needed.
77d3d7b
to
4cc58e2
Compare
Otherwise it complains that it cannot find the types, understandably.
The idea is to fully type-hint
natsort
and make it 100% clean tomypy
in--strict
mode. We'll see if we get there :)