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

usjon: Add default keyword argument #8729

Closed
wants to merge 1 commit into from
Closed

usjon: Add default keyword argument #8729

wants to merge 1 commit into from

Conversation

antoniobusrod
Copy link

Add missing default keyword argument to dump and dumps functions.

Introduced since https://github.com/ultrajson/ultrajson/releases/tag/4.2.0

Relates to ultrajson/ultrajson#470

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is actually a function that gets called with one argument to get the default value, so we can use Callable[[Any], Any] instead of just Any.

>>> ujson.encode({'a': object()}, default=(lambda x: "lol"))
'{"a":"lol"}'

We should also add this parameter to dump().

>>> ujson.dump({'a': object()}, sys.stdout, default=(lambda x: "lol"))
{"a":"lol"}>>> 

@Akuli
Copy link
Collaborator

Akuli commented Sep 12, 2022

It also seems like most of the arguments are keyword-only, even though they aren't marked as keyword-only in the stub:

>>> ujson.dump({'a': object()}, sys.stdout, True, 1, True, True, True, 1, (lambda x: "lol"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function takes exactly 2 arguments (9 given)

We can fix this in a separate pull request.

@JelleZijlstra
Copy link
Member

Could you address @Akuli's feedback?

@AlexWaygood
Copy link
Member

Closing due to lack of response from OP

@antoniobusrod antoniobusrod deleted the add-missing-default-keyword-argument branch December 13, 2022 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants