-
Notifications
You must be signed in to change notification settings - Fork 517
Implements JS Blob API in Python SDK #3096
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
Conversation
639ee07 to
1be5011
Compare
| # TODO: Pyodide's FetchResponse.headers returns a dict[str, str] which means | ||
| # duplicates are lost, we should fix that so it returns a http.client.HTTPMessage |
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.
Do you still think we should do this? I thought the duplicate values are combined with a comma. How does http.client.HTTPMessage handle values with a comma in them?
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.
It's not super important, but it would be nice. Splitting values by comma is pretty bleh as far as API design.
But I guess on the other hand that is what JS' Headers expects so maybe it's fine.
1be5011 to
221588e
Compare
221588e to
456d192
Compare
4381834 to
46f1485
Compare
src/pyodide/internal/workers.py
Outdated
| **options: Unpack[BlobKwargs], | ||
| ): | ||
| if "content_type" in options: | ||
| options["type"] = options["content_type"] | ||
| if "endings" in options: | ||
| options["endings"] = str(options["endings"]) |
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.
Seems like it might be better to be explicit here:
| **options: Unpack[BlobKwargs], | |
| ): | |
| if "content_type" in options: | |
| options["type"] = options["content_type"] | |
| if "endings" in options: | |
| options["endings"] = str(options["endings"]) | |
| content_type: str | None = None, | |
| endings: BlobEnding | str | None = None | |
| ): | |
| if endings: | |
| endings = str(endings) |
and then:
js.Blob.new(args, type=content_type, endings=endings)Also, I am pretty sure that you don't need to_js for args.
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.
Also, I am pretty sure that you don't need to_js for args.
You do, I get this otherwise: pyodide.ffi.JsException: TypeError: Failed to construct 'Blob': constructor parameter 1 is not of type 'Array'.
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.
That's unfortunate. There's been discussion before whether we should make Array.isArray() return true on a Python list. Not sure whether it would fix this error message. I also don't remember why I didn't do it -- it's possible I just never got to it, or that there was some problem it caused.
46f1485 to
a5da0fc
Compare
a5da0fc to
c30f37a
Compare
hoodmane
left a comment
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.
Looking pretty good now, thanks @dom96. I have one last remark.
c30f37a to
f04a34e
Compare
0dec886 to
548b5f1
Compare
548b5f1 to
fbb1fba
Compare
fbb1fba to
a75d9dc
Compare
The big change here is the addition of the Blob API. But there are also some other improvements/fixes:
js_objectproperty which returns its underlying JS object.Test Plan