-
Notifications
You must be signed in to change notification settings - Fork 172
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
issue/97 accept path like objects for file uploads #463
issue/97 accept path like objects for file uploads #463
Conversation
Ok. strangely this works in the test suite but not in my downstream (fails in an actual upload). It appears the tests I added were not sufficient. I recommend not merging this yet til I figure out how to properly test this & fix the bug. |
canvasapi/upload.py
Outdated
self.kwargs["name"] = os.path.basename(file.name) | ||
self.kwargs["size"] = os.fstat(file.fileno()).st_size | ||
if isinstance(file, Path): | ||
self.kwargs.update({"name": file.name, "size": file.stat().st_size}) |
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.
From what I can see, I think this code is unreachable with our current public API. We open the file before we call get_upload_token
, so it's never a Path
.
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.
I believe that's correct, this change can likely be reverted.
IIRC I added this check while debugging something and didn't remove it after.
So, the good (and probably obvious) news: The changes work! Still able to upload files (paths and file handlers alike). This is almost ready to go, but I have a question re: coverage. Our coverage drops here because of the |
Sounds logical to me. pushed a commit to address that point. |
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.
Thanks for your work on this! LGTM 👍
Proposed Changes
Add
canvas.upload.FileOrPathLike
type, which represents anyos.PathLike
,str
, orio
based file like and path like objects.Add support in
canvas.upload.Upload
to accept anyFileOrPathLike
, as per #97 /Add type annotations to all consumers of
file
arguments which are forwarded intocanvas.upload.Upload
.Added two tests that use
pathlib.Path
objects to assert correctness.Fixes #97 .