lunr.py icon indicating copy to clipboard operation
lunr.py copied to clipboard

Enable type checking for users and add types to nearly everything

Open dhdaines opened this issue 1 year ago • 6 comments

Some of the code (pipeline.py) had some types. But this wasn't super useful because the magical py.typed file was not included in the package.

So this adds that, but also adds some types.

I can't totally figure out how to use Protocol correctly for pipeline functions but in actual fact they have a fixed signature, and the attributes we add are purely for internal use, so it's type: ignore for the time being.

dhdaines avatar Jul 06 '24 01:07 dhdaines

fixes #158

dhdaines avatar Jul 06 '24 03:07 dhdaines

I got carried away and added types nearly everywhere.

For CompleteSet there is an issue since its API is quite strange (though I understand the intent)

For Vector this can't be done efficiently because it relies on mixing str and float everywhere including in the values, so numeric calculations are simply undefined for string vectors (otherwise we'd have to cal isinstance repeatedly, which is super slow)

dhdaines avatar Jul 06 '24 14:07 dhdaines

Final comment: any good reason why boost needs to be an int? It's a number in lunr.js and it just gets multiplied into a float anyway at some point.

dhdaines avatar Jul 06 '24 14:07 dhdaines

Formatted, type-checked, toxed, squashed and force-pushed!

dhdaines avatar Sep 09 '24 14:09 dhdaines

The PR will likely need reformatting and I suggest squashing the commits as well, but thanks for separating things so it's easier to review.

Question - should I rebase the other PRs on top of this one? That will take some editing because of all of the types.

dhdaines avatar Sep 09 '24 14:09 dhdaines

Codecov Report

Attention: Patch coverage is 95.60000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 95.82%. Comparing base (d07b60f) to head (5a2f171).

Files with missing lines Patch % Lines
lunr/index.py 82.97% 8 Missing :warning:
lunr/match_data.py 88.88% 1 Missing :warning:
lunr/query_parser.py 95.83% 1 Missing :warning:
lunr/token_set.py 95.83% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #156      +/-   ##
==========================================
- Coverage   96.02%   95.82%   -0.21%     
==========================================
  Files          48       48              
  Lines        3171     3257      +86     
==========================================
+ Hits         3045     3121      +76     
- Misses        126      136      +10     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Sep 09 '24 14:09 codecov-commenter