Assert label values be str or unicode#177
Closed
kehao95 wants to merge 1 commit intoprometheus:masterfrom
Closed
Conversation
Author
|
After patch: |
df8959c to
4831c4c
Compare
| labels: A list of label values | ||
| value: The value of the metric. | ||
| ''' | ||
| try: |
Contributor
There was a problem hiding this comment.
It'd be more Pythonic to duck type and to convert a string, rather than limit to two particular classes.
This needs a unittest
Author
There was a problem hiding this comment.
Ah yes, I wish I could think up a more Pythonic way.
I found this Question in StackOverflow
https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility
The best one needs six. I have no idea.
Author
There was a problem hiding this comment.
I reviewed the string_types definition in the six project.
GitHub-benjaminp/six
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
Contributor
There was a problem hiding this comment.
Technically what we need here is a utf8 string.
Contributor
|
This is stale. |
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.
Right now, if you call add_metric() method with no string variables. Nothing will happen. But will raise meanless AttributError when first scrape.
quick reproduce
When you try to scrape the metrics, it will raise a helpless Tracback.