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
Support Enum query params #2515
Changes from 1 commit
4c5a884
b583641
98e5ad7
7a33454
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import codecs | ||
import email.message | ||
import enum | ||
import logging | ||
import mimetypes | ||
import netrc | ||
|
@@ -67,6 +68,8 @@ def primitive_value_to_str(value: "PrimitiveData") -> str: | |
return "false" | ||
elif value is None: | ||
return "" | ||
elif isinstance(value, enum.Enum): | ||
return str(value.value) | ||
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this imply that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I miss that. Do you think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honest answer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a similar example... import json
json.dumps{"value": Color.RED} # TypeError: Object of type Color is not JSON serializable
json.dumps{"value": Color.RED.value} # '{"value": 1}' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is... I think the following should raise an error: class Color(enum.Enum):
RED = 1
GREEN = 2
BLUE = 3 But not the following: class Color(int, enum.Enum):
RED = 1
GREEN = 2
BLUE = 3 Because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm. That's a bit awkward... class Color(str, enum.Enum):
# heeeeyyyyyy I'm just a normal str
RED = "red"
GREEN = "green"
BLUE = "blue"
c = Color.RED
isinstance(c, str) # True
str(c) # 'Color.RED' yeah but you ain't The upshot is even if you're type-checking the user still needs to correctly pass Maybe the upshot is we should have strict type checking here and that we should also expand the primitive types to include (Or maybe the upshot is that users should pass the enum value, because we're cold hard calculating types, and we like precision) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If I understood correctly what you said, this is not the case. Type checkers understand that each member of a (str, Enum) is a str, and they don't raise errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think requests has the same behavior as httpx here, does it? Because the Testclient changed, so I assume requests can do the "right" thing on (str, Enum) - I'm on my phone. |
||
return str(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd be happier if HTTPX had an extra branch For Is my thinking, at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Should I proceed? Aren't we going to have some side effects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was kind of what happened on #2523, and we had to revert. |
||
|
||
|
||
|
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.
This was unused.