Skip to content
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

monkey.py default should use bounded default method. #323

Closed
doranid opened this issue Jan 24, 2021 · 3 comments · Fixed by #324
Closed

monkey.py default should use bounded default method. #323

doranid opened this issue Jan 24, 2021 · 3 comments · Fixed by #324
Assignees
Labels

Comments

@doranid
Copy link

doranid commented Jan 24, 2021

Currently, monkey.py calls _default.default(obj).
But, _default.default is json.JSONEncoder.default, which is an unbounded method, so it needs two arguments for a successful call. A possible solution is to define _default.default = json.JSONEncoder().default instead.

How to reproduce:

 import json
 import pottery
 json.dumps(object())

Will throw an error

TypeError: default() missing 1 required positional argument: 'o'

Instead of an error

TypeError: Object of type 'object' is not JSON serializable
brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
@brainix
Copy link
Owner

brainix commented Jan 25, 2021

Thanks for the bug report. I've submitted a PR here: #324

How does it look, @doranid?

@brainix brainix self-assigned this Jan 25, 2021
@brainix brainix added the bug label Jan 25, 2021
@brainix brainix linked a pull request Jan 25, 2021 that will close this issue
@doranid
Copy link
Author

doranid commented Jan 25, 2021

Thanks for the bug report. I've submitted a PR here: #324

How does it look, @doranid?

Seems good, thanks!

brainix added a commit that referenced this issue Jan 25, 2021
Previously, our JSON encoder monkey patch was to an unbound method.
This resulted in throwing a misleading `TypeError` when trying to encode
something non-encodable.
@brainix
Copy link
Owner

brainix commented Jan 26, 2021

I've released Pottery 1.1.1 which includes this fix. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants