-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-44149: Add key
argument to difflib.get_close_matches()
#26170
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
base: main
Are you sure you want to change the base?
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Lib/difflib.py
Outdated
@@ -710,11 +710,18 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6): | |||
Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities | |||
that don't score at least that similar to word are ignored. | |||
|
|||
Optional arg key specifies a function of one argument that is used to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under the impression the trailing whitespace at this and the following line cause travis to complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for pointing it out. I'll update this along with the other changes.
The docs should definitely be updated for this. I also see a test for this specific function does not exist yet, this seems like a good chance to add one? |
@DimitrisJim , thanks for the feedback. I'm still new to the project, and would like to help out with this, so can you point me as to how to go about this? From what I see the documentation for this function looks like it has been auto-generated from the docstrings, and the tests (which I can run with Is there a more official place to put these? I'm not 100% confident on the internal algorithms for |
Of course! Docs are relatively straight-forward to add, from what I remember, they aren't built automatically. The Devguide section on this explains most of what you'll need to know. It basically boils down to opening the corresponding file for difflib in the For tests, usually you'd add a unit test to |
This PR is stale because it has been open for 30 days with no activity. |
@tim-one any chance you could review this anytime soon? It's a pretty minor change. |
Please add to Docs as get_close_matches(word, possibilities, n=3, cutoff=0.6) needs changing. Also, please add version changed: 3.12 (is earliest). |
https://bugs.python.org/issue44149
This features allows you to specify a key function to extract the correct value from an element to be able to find close matches. Currently the only way to do it without re-implementing the function is to extract all the strings into a list, find the close matches and then once again go through the objects to find the corresponding ones.
A simple test case has also been added, and documentation within the file updated as well.
https://bugs.python.org/issue44149