yeraydiazdiaz / lunr.py

A Python implementation of Lunr.js 🌖
http://lunr.readthedocs.io
MIT License
187 stars 16 forks source link

Enable type checking for users and add types to nearly everything #156

Open dhdaines opened 1 month ago

dhdaines commented 1 month ago

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 commented 1 month ago

fixes #158

dhdaines commented 1 month ago

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 commented 1 month ago

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.