Skip to content
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

Bucket: add string representation and equality method #1095

Merged
merged 3 commits into from
May 24, 2021

Conversation

GreatBahram
Copy link
Contributor

Hello there,

I added these changes for multiple reasons,

  • First of all, when I'm dealing with buckets they lack string representation which is handly some use cases:
In [4]: client.list_buckets()
Out[4]: 
[<minio.datatypes.Bucket at 0x7f15f097dc70>,
 <minio.datatypes.Bucket at 0x7f15eaae73d0>]

In [5]: # It could have been something like this:
Out[5]: [Bucket('a'), Bucket('b')]
# or this scenario:

In [6]: for b in client.list_buckets():
   ...:     print(b)
   ...: 
<minio.datatypes.Bucket object at 0x7f15eb4c4cd0>
<minio.datatypes.Bucket object at 0x7f15eaedda00>
# Instead:
In [7]: for b in client.list_buckets():
    ...:     print(b)
    ...: 
a
b

But more importantly, I wanted to check if a specific bucket exists inside a list of buckets, I know I can use bucket_exists method, but it's good to have an equality method for bucket object:

In [7]: 'a' in client.list_buckets()
Out[7]: False
In [8]: 'a' in client.list_buckets() # when you have __eq__ method for bucket obj
Out[8]: True

balamurugana
balamurugana previously approved these changes Mar 9, 2021
@balamurugana balamurugana changed the title add string representation as well as equality method Bucket: add string representation and equality method Mar 9, 2021
@GreatBahram
Copy link
Contributor Author

I also added __hash__ method, because in the past it was possible to use bucket objects inside a set or a dictionary.

@GreatBahram
Copy link
Contributor Author

GreatBahram commented Mar 15, 2021

Do you think it's a good idea to add these methods for the Object class as well? @balamurugana

@harshavardhana harshavardhana merged commit df3e895 into minio:master May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants