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

Make classes inheriting from Type hashable #1944

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

ricardobranco777
Copy link
Contributor

@ricardobranco777 ricardobranco777 commented Aug 21, 2023

Make classes inheriting from Type hashable

Description

Attributes of classes that inherit from libcloud.common.types.Type are not hashable, so they can't be tested for membership in sets, unlike those that inherit from libcloud.container.types.Type which work as intended.

$ python
Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from libcloud.compute.types import NodeState
>>> NodeState.RUNNING
running
>>> NodeState.RUNNING in {"running"}
False
>>> str(NodeState.RUNNING) in {"running"}
True
>>> from libcloud.container.types import ContainerState
>>> ContainerState.RUNNING in {"running"}
True

Status

done, ready for review.

Checklist (tick everything that applies)

  • Code linting (required, can be done after the PR checks)
  • Documentation
  • Tests
  • ICLA (required for bigger changes)

@Kami
Copy link
Member

Kami commented Aug 22, 2023

Thanks for the contribution.

The change looks good to me, but can you add a a couple of simple unit tests for it so we can get it merged?

@Kami
Copy link
Member

Kami commented Aug 22, 2023

I also had a quick look at the container Type implementation and it appears it doesn't define __hash__ and all the other special methods defined by the libcloud.common.Type.

It seems like that for consistency reasons, libcloud.container.Type should eventually be made to inherit from libcloud.common.type.

An alternative could perhaps also be to completely remove those methods since it appear they are only present for backward compatibility reasons (

). But before doing that, we would of course first need to analyze and understand the impact of such change.

@codecov-commenter
Copy link

Codecov Report

Merging #1944 (82780c9) into trunk (abba8c1) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##            trunk    #1944   +/-   ##
=======================================
  Coverage   83.18%   83.18%           
=======================================
  Files         352      352           
  Lines       81324    81324           
  Branches     8579     8579           
=======================================
  Hits        67647    67647           
  Misses      10873    10873           
  Partials     2804     2804           
Files Changed Coverage Δ
libcloud/common/types.py 97.06% <100.00%> (ø)

@ricardobranco777
Copy link
Contributor Author

The change looks good to me, but can you add a a couple of simple unit tests for it so we can get it merged?

Done.

It seems like that for consistency reasons, libcloud.container.Type should eventually be made to inherit from libcloud.common.type.

I'm very much in favour of doing that if we remove the dunder methods.

@Kami
Copy link
Member

Kami commented Sep 13, 2023

@ricardobranco777

Thanks.

I'm very much in favour of doing that if we remove the dunder methods.

To be on the safe side, I think it's better to do this in a separate add-on PR once this one is merged.

asfgit pushed a commit that referenced this pull request Sep 13, 2023
@asfgit asfgit merged commit b774d31 into apache:trunk Sep 13, 2023
17 of 18 checks passed
@Kami
Copy link
Member

Kami commented Sep 13, 2023

The PR has been merged.

It seems like that for consistency reasons, libcloud.container.Type should eventually be made to inherit from libcloud.common.type.

Once you get a chance, it would be great if you could make this change and also get rid of all the dunder methods which are there for backward compatibility reasons with older versions of Libcloud before Type inherited from Enum. We just need to test it and ensure that this change won't break anything.

Thanks.

@Kami Kami added this to the v3.9.0 milestone Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants