-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
smart_open/s3: Initial implementations of str and repr #359
Changes from 1 commit
25b4cb3
d0d533d
899d314
a440d10
c86674c
3523dc8
ecaabd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -412,6 +412,14 @@ def truncate(self, size=None): | |||||
"""Unsupported.""" | ||||||
raise io.UnsupportedOperation | ||||||
|
||||||
def __str__(self): | ||||||
return "s3.SeekableBufferedInputBase(bucket_name='{}', key='{}')".format( | ||||||
self._object.bucket_name, self._object.key) | ||||||
|
||||||
def __repr__(self): | ||||||
return "s3.SeekableBufferedInputBase(bucket_name='{}', key='{}')".format( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to include the full package name here. It'll be helpful for people outside of smart_open: they'll know what package the class comes from.
Suggested change
|
||||||
self._object.bucket_name, self._object.key) | ||||||
|
||||||
|
||||||
class BufferedOutputBase(io.BufferedIOBase): | ||||||
"""Writes bytes to S3. | ||||||
|
@@ -553,6 +561,13 @@ def __exit__(self, exc_type, exc_val, exc_tb): | |||||
else: | ||||||
self.close() | ||||||
|
||||||
def __str__(self): | ||||||
return "s3.BufferedOutputBase(bucket_name='{}', key='{}')".format( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. str should prioritize brevity:
Suggested change
Also please avoid using the .format() stuff (we don't like it). |
||||||
self._object.bucket_name, self._object.key) | ||||||
|
||||||
def __repr__(self): | ||||||
return "s3.BufferedOutputBase(bucket_name='{}', key='{}')".format( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check out this link for an explanation of the difference between str and repr. My understanding is that with repr, the user should be able to copy-paste the result into the Python interpreter and get back a copy of the original object. This may not always be possible, but this is something we should aim for. So, please include all the parameters passed to the constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback! I've introduced most of the suggested changes, but I'd say that this one is still somewhat incomplete. As you said, sometimes these constructor parameters are not available and here we have a similar case where the values passed to the constructor are used to create other objects and the values themselves aren't stored anywhere. I could try digging through the implementations of these other objects to find the values, but that seems hacky. Would it be OK if these parameters were stored in SeekableBufferedInputBase or BufferedOutputBase objects as in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I think it makes sense to store them. |
||||||
self._object.bucket_name, self._object.key) | ||||||
|
||||||
def iter_bucket(bucket_name, prefix='', accept_key=None, | ||||||
key_limit=None, workers=16, retries=3): | ||||||
|
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 you please use hanging indents?