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

Full inlined type hints for thefuzz.process #71

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

mjpieters
Copy link
Contributor

Provides full type hinting for the process module functions.

I have followed the typing best practices where possible, without having to add a dependency on typing_extensions. This
means:

  • I inlined the type annotations so they won't be overlooked when making changes to the module. Stub files are great for extension modules, not so great for pure-Python projects.
  • To keep compatibility with Python 3.8, I didn't mark the type aliases (_Processor, etc.) with TypeAlias. This isn't necessary anyway as none of the aliases use forward references. The annotations use typing.Union[] and typing.Optional[] instead of the newer | syntax for the same reason.
  • Inputs use the most permissable container ABC possible; e.g. contains_dupes only needs to support iteration and length. Return types are the most specific type.

Note that dedupe() explicitly states it can return a list of strings or the original container type.

The types have been verified against the rapidfuzz annotations and sourcecode, with the exception of the query and choice types, which have been constrained here to str. It is possible to extend this to support more types if necessary, but then we'd need to add another typevar and use this in the _Processor and _Scorer type aliases too, which complicates matters. Since all the default processors only accept strings I thought this a good compromise.

@johnthedebs johnthedebs merged commit 83bea3d into seatgeek:master Feb 27, 2024
@mjpieters mjpieters deleted the process_types branch March 7, 2024 21:27
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.

2 participants