-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
🐛 Fix encoding data with None values and more #119
Conversation
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.
the test only make sure the error does not occurs. we should verify that the "None" values are excluded.
@Ousret, you're totally right. I had how requests handles the import niquests
import requests
class Class:
pass
class ClassStringable:
def __str__(self):
return "🔥arbClassStringable🔥"
url = "https://httpbin.org/post"
body = {
"string": "string",
"float": 0.01,
"int": 100,
"bool": True,
"None": None,
"plain_class": Class(),
"stringable_class": ClassStringable(),
}
resp_re = requests.post(url, data = body)
resp_ni = niquests.post(url, data = body)
for key in ['args', 'data','files','form','json']:
try:
assert resp_re.json()[key] == resp_ni.json()[key]
except AssertionError:
print(resp_re.json()[key],'\n\n\n',resp_ni.json()[key]) |
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.
Almost there.
**Fixed** - Fixed encoding data with None values and other objects. This was a regression introduced in our v3. #119 **Changed** - Various minor performance improvements.
**Fixed** - Fixed encoding data with None values and other objects. This was a regression introduced in our v3. #119 **Changed** - Various minor performance improvements.
This addresses #118, inspired by the code in requests.
Essentially this PR will allow encoding any non-iterable object as string. This is a general solution to the specific problem in #118. Since
None
is not iterable, it is encoded "None". Similarly, any non-iterable object will be encoded asstr(obj)
.