liormizr / s3path

s3path is a pathlib extension for AWS S3 Service
Apache License 2.0
206 stars 39 forks source link

Would it make sense to add a __str__ method to these classes? #133

Closed ryanrichholt closed 5 months ago

ryanrichholt commented 1 year ago

Hi - I just started using this package, and I'm loving it so far. But, I'm having trouble understanding why the string representation isn't just a URI? For example, with this package I can deal with a set of paths that are a mix of local Path and S3Path objects, which is awesome. But when logging or printing the paths it's hard to tell which is which.

>>> paths = [
...     Path('/scratch/user/file.txt'),
...     Path.home().joinpath('file.txt'),
...     S3Path.from_uri('s3://bucketname/pref/filename.txt'),
... ]
>>> for path in paths:
...     print(path)
...
/scratch/user/file.txt
/Users/username/file.txt
/bucketname/pref/filename.txt

I work around this now by just using the repr() and fstring formatting log.info(f'example log message: {path!r}'). But, wouldn't it make sense to have the __str__ method of the S3Path class emit the URI?

liormizr commented 1 year ago

Hi @ryanrichholt

Thanks for the issue and I'm glad to hear that you are working with our package :-) We had a similar discussion in issue #59

Basically I agree with you that the best approach was if in pathlib Path.srt was actually returning the uri value that was perfect. Unfortunately it's not like that. And we are trying the keep s3path as closely to the source implementation as possible.

We can keep this issue open. I'll like to hear more from other users if this is something that we want to change. If we will change this behavior this is a big change that will require a major version upgrade