Skip to content

Conversation

@Michael0x2a
Copy link
Contributor

This pull request adds stubs for ujson. Note that the interface for ujson is a bit more restrictive then the interface for the json module in the standard library.

@gvanrossum
Copy link
Member

Have you checked with the developers of ujson whether they are okay with including these stubs in typeshed? Our policy for third_party packages requires checking this. You can probably just ask them in their tracker and once they respond, link back to their tracker issue here.

@gvanrossum
Copy link
Member

PS. Would be nice if we had a bot that automatically asked that whenever someone submits stubs for a new package in third_party.

@Michael0x2a
Copy link
Contributor Author

I asked them just now, and they were ok with it: ultrajson/ultrajson#233

@gvanrossum gvanrossum merged commit 313b584 into python:master Aug 12, 2016
@Michael0x2a Michael0x2a deleted the add-ujson branch September 9, 2016 18:50
@timabbott
Copy link
Contributor

@Michael0x2a how confident are you that the ujson methods take a str (as opposed to e.g. an AnyStr)? I haven't looked too closely, but based on ultrajson/ultrajson#11, it seems current ujson is intended to return a unicode if you pass it a unicode, I think?

@timabbott
Copy link
Contributor

timabbott commented Sep 10, 2016

(For context, I'm getting errors trying to use this with the Zulip project, which has annotations assuming that e.g. ujson.loads can be passed a Text object. It's possible those annotations are wrong, but I'd be a bit surprised...)

@gvanrossum
Copy link
Member

gvanrossum commented Sep 10, 2016 via email

@Michael0x2a
Copy link
Contributor Author

Hmm, you might be right -- in retrospect, I'm not sure if I tested my stubs very thoroughly on Python 2.

I did some quick testing, and it seems like the loads functions most likely can take in strings of type Union[Text, bytes]. The dumps functions seem a bit more complicated -- they seem to return str in both Python 2 and Python 3 (which means they're really returning bytes in Python 2 and Text in Python 3?).

But perhaps I'm wrong about this again.

@timabbott
Copy link
Contributor

Yeah, I just tested as well and indeed loads at least can take Text and bytes.

timabbott added a commit to timabbott/typeshed that referenced this pull request Sep 13, 2016
The ujson module apparently will accept both bytes and text format
input, however, it does always output a str (both on Python 2 and
Python 3).

Some discussion in: python#460
@timabbott
Copy link
Contributor

Opened #540 to fix this issue. Thanks @Michael0x2a for also investigating this :)

gvanrossum pushed a commit that referenced this pull request Sep 13, 2016
The ujson module apparently will accept both bytes and text format
input, however, it does always output a str (both on Python 2 and
Python 3).

Some discussion in: #460
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.

4 participants