Repository navigation
Accept label keyword arguments in remove() - #1227
Open
Thanatos9404 wants to merge 1 commit into
Open
Thanatos9404 wants to merge 1 commit into
Thanatos9404 wants to merge 1 commit into
Conversation
labels() takes the label values positionally or as keyword arguments, but remove() only took them positionally, so a child created with c.labels(method='get', endpoint='/') had to be removed with the values in labelnames order. Let remove() take keyword arguments with the same rules as labels(): one for every label name, matched by name, and not mixed with positional values. Move its docstring to the top of the function, where it was not picked up as a docstring. Fixes prometheus#820 Signed-off-by: Yashvardhan Thanvi <yashvt9404@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #820
@csmarchbanks, as discussed in the issue:
labels()takes the label values positionally or as keyword arguments, butremove()only took them positionally, so a child created withc.labels(method='get', endpoint='/')had to be removed withc.remove('get', '/'), inlabelnamesorder.remove()now takes keyword arguments with the same rules aslabels():ValueError, same message aslabels());ValueError.This is different from
remove_by_labels(), which removes every labelset that partially matches a dict (so leaving a label out widens the match) and scans all children.remove()with keywords still deletes exactly one labelset and checks that every label name is given, likelabels().I also moved the
remove()docstring to the top of the function: it sat after the first statements, so it wasn't the function's docstring. The labels docs now show the keyword form.Tests in
tests/test_core.py: removal by keyword, matching by name when the keyword order differs fromlabelnames, theValueErrorcases (mixed, missing, unknown and extra names),str()coercion (remove(l=None)), and the keyword form intest_recreate_child_after_removal. The 5 new or extended tests fail on master withTypeError: ... got an unexpected keyword argument.Run locally: the full
pytestsuite on Linux with Python 3.12 (431 passed, 14 skipped),tox -e mypy's command (mypy 0.991 on Python 3.9: no issues), and theflake8andisort --checkcommands fromtox.ini.