-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support google file api urls #2270
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
base: main
Are you sure you want to change the base?
Conversation
@@ -92,6 +92,9 @@ class FileUrl(ABC): | |||
url: str | |||
"""The URL of the file.""" | |||
|
|||
_media_type: str | None = field(default=None, repr=False) |
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.
@DouweM I diverged from your proposition of setting media_type
in the __post_init__
, because I realized (after the fact...) that it would make it mandatory to specify it in cases where it's not needed/relevant, e.g. when force_download==True
or when it's a youtube video url. (I figured making the field optional would be too messy)
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.
Ok, defining it as a private field (with the underscore) makes sense, but since we want users to set this, the keyword argument on the constructor should not have an underscore. So I think we'll need a custom __init__
method (and overrides on the subclasses)
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 did it using an InitVar
+ __post_init__
to avoid having to define the whole init for FileUrl
+ subclasses. Is that ok?
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 commented below but the argument really should be media_type
without the confusing final underscore. Since this is a library, the cleanness of the public interface is more important than the cleanness of the code to make it work. :)
@@ -92,6 +92,9 @@ class FileUrl(ABC): | |||
url: str | |||
"""The URL of the file.""" | |||
|
|||
_media_type: str | None = field(default=None, repr=False) |
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.
Ok, defining it as a private field (with the underscore) makes sense, but since we want users to set this, the keyword argument on the constructor should not have an underscore. So I think we'll need a custom __init__
method (and overrides on the subclasses)
document_url = DocumentUrl(url='https://example.com/document.pdf') | ||
assert document_url.media_type == 'application/pdf' | ||
assert document_url.format == 'pdf' | ||
|
||
document_url = DocumentUrl(url='https://example.com/document', media_type_='application/pdf') |
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.
Can't we make the argument media_type
? That may require a custom __init__
.
Uh oh!
There was an error while loading. Please reload this page.