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

Type hinting #138

Merged
merged 25 commits into from
Nov 3, 2021
Merged

Type hinting #138

merged 25 commits into from
Nov 3, 2021

Conversation

SethMMorton
Copy link
Owner

The idea is to fully type-hint natsort and make it 100% clean to mypy in --strict mode. We'll see if we get there :)

thethiny and others added 6 commits August 31, 2021 17:33
Added support for type hinting for consistency with `sorted` from builtints.
This allows Iterables of Custom Objects to be typed.
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.
@insilications
Copy link

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
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #138 (3461338) into master (afe1226) will decrease coverage by 2.78%.
The diff coverage is 93.47%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
natsort/natsort.py 90.47% <82.27%> (-9.53%) ⬇️
natsort/utils.py 98.31% <96.11%> (-1.69%) ⬇️
natsort/__init__.py 100.00% <100.00%> (ø)
natsort/__main__.py 100.00% <100.00%> (ø)
natsort/compat/fake_fastnumbers.py 100.00% <100.00%> (ø)
natsort/compat/fastnumbers.py 92.85% <100.00%> (+0.54%) ⬆️
natsort/compat/locale.py 95.74% <100.00%> (+0.50%) ⬆️
natsort/ns_enum.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afe1226...3461338. Read the comment docs.

@SethMMorton
Copy link
Owner Author

Huzzah! Before I merge this, I think I want to add type hints to fastnumbers so that I don't need to ignore that package in the mypy configuration.

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.
Otherwise it complains that it cannot find the types, understandably.
@SethMMorton SethMMorton merged commit 5eaed41 into master Nov 3, 2021
@SethMMorton SethMMorton deleted the type-hinting branch November 3, 2021 02:52
@SethMMorton SethMMorton mentioned this pull request Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants