Skip to content

Commit

Permalink
Merge branch 'trunk' into dependabot/pip/sphinx-rtd-theme-1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami authored Sep 13, 2023
2 parents 7ba3892 + b96bf0e commit 5e2a01b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/depsreview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

Changes in Apache Libcloud in development
-----------------------------------------

Common
~~~~~~

- Types inheriting from ``libcloud.common.types.Type`` have been made hashable.
This way they can be directly used for testing memberships in sets which
contain string representation of the type enum value
(e.g. ``NodeState.RUNNING in {"running"} == True``).
(#1944)
[Ricardo Branco - @ricardobranco777]

Changes in Apache Libcloud 3.8.0
--------------------------------

Expand Down
2 changes: 1 addition & 1 deletion libcloud/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __repr__(self):
return self.value

def __hash__(self):
return id(self)
return hash(self.value)


class LibcloudError(Exception):
Expand Down
32 changes: 32 additions & 0 deletions libcloud/test/common/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from libcloud.common.types import Type
from libcloud.compute.types import NodeState


class TypeTest(unittest.TestCase):
def test_Type(self):
class TestType(Type):
TESTING = "testing"

self.assertEqual(hash(TestType.TESTING), hash("testing"))
self.assertIn(TestType.TESTING, {"testing"})

def test_NodeState(self):
self.assertEqual(hash(NodeState.RUNNING), hash("running"))
self.assertIn(NodeState.RUNNING, {"running"})

0 comments on commit 5e2a01b

Please sign in to comment.