Skip to content

Commit 4c2716f

Browse files
ogajduseclaudeCopilot
authored
Fix ruff linting issues to prepare for version bump (#1328)
* Fix ruff linting issues to prepare for version bump - Add __hash__ method to Entity class (PLW1641) - Fix dictionary iteration to use .items() (PLC0206) - Add noqa comments for intentional mid-function imports (PLC0415) All tests pass and ruff linting now succeeds with no errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Apply pre-commit automated fixes - Black formatting for nailgun/entities.py - Ruff removed unnecessary noqa comments (PLC0415 no longer flagged) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update nailgun/entity_mixins.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6b595fe commit 4c2716f

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

nailgun/entities.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4985,10 +4985,8 @@ def read(self, entity=None, attrs=None, ignore=None, params=None):
49854985
# Ignore puppetclass attribute if we are running against Puppet disabled
49864986
# instance. Ignore it also if the API does not return puppetclasses for
49874987
# the given host, but only if it does not have Puppet proxy assigned.
4988-
if (
4989-
'Puppet' not in _feature_list(self._server_config)
4990-
or 'puppetclasses' not in attrs
4991-
and not attrs['puppet_proxy']
4988+
if 'Puppet' not in _feature_list(self._server_config) or (
4989+
'puppetclasses' not in attrs and not attrs['puppet_proxy']
49924990
):
49934991
ignore.add('puppetclass')
49944992
result = super().read(entity, attrs, ignore, params)

nailgun/entity_mixins.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ def __eq__(self, other):
614614
return False
615615
return self.to_json_dict() == other.to_json_dict()
616616

617+
def __hash__(self):
618+
"""Return hash based on entity type and id if available."""
619+
if getattr(self, 'id', None) is not None:
620+
return hash((type(self), self.id))
621+
return hash(type(self))
622+
617623
def compare(self, other, filter_fcn=None):
618624
"""Return True if properties can be compared in terms of eq.
619625

tests/test_entities.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,15 +3013,15 @@ def test_add_func_with_id(self):
30133013
entity = self.entity
30143014
entity.id = 1
30153015
func_param_dict = {entity.add_ansible_role: 'ansible_role_id'}
3016-
for func in func_param_dict:
3016+
for func, param in func_param_dict.items():
30173017
self.assertEqual(inspect.getfullargspec(func), EXPECTED_ARGSPEC)
3018-
kwargs = {'kwarg': gen_integer(), 'data': {func_param_dict[func]: gen_integer()}}
3018+
kwargs = {'kwarg': gen_integer(), 'data': {param: gen_integer()}}
30193019
with mock.patch.object(entities, '_handle_response') as handlr:
30203020
with mock.patch.object(client, 'put') as client_request:
30213021
response = func(**kwargs)
30223022
self.assertEqual(client_request.call_count, 1)
30233023
self.assertEqual(len(client_request.call_args[0]), 1)
3024-
self.assertNotIn(func_param_dict[func], client_request.call_args[1]['data'])
3024+
self.assertNotIn(param, client_request.call_args[1]['data'])
30253025
self.assertEqual(client_request.call_args[1], kwargs)
30263026
self.assertEqual(handlr.call_count, 1)
30273027
self.assertEqual(handlr.return_value, response)
@@ -3044,15 +3044,15 @@ def test_delete_func_with_id(self):
30443044
entity.delete_puppetclass: 'puppetclass_id',
30453045
entity.remove_ansible_role: 'ansible_role_id',
30463046
}
3047-
for func in func_param_dict:
3047+
for func, param in func_param_dict.items():
30483048
self.assertEqual(inspect.getfullargspec(func), EXPECTED_ARGSPEC)
3049-
kwargs = {'kwarg': gen_integer(), 'data': {func_param_dict[func]: gen_integer()}}
3049+
kwargs = {'kwarg': gen_integer(), 'data': {param: gen_integer()}}
30503050
with mock.patch.object(entities, '_handle_response') as handlr:
30513051
with mock.patch.object(client, 'delete') as client_request:
30523052
response = func(**kwargs)
30533053
self.assertEqual(client_request.call_count, 1)
30543054
self.assertEqual(len(client_request.call_args[0]), 1)
3055-
self.assertNotIn(func_param_dict[func], client_request.call_args[1]['data'])
3055+
self.assertNotIn(param, client_request.call_args[1]['data'])
30563056
self.assertEqual(client_request.call_args[1], kwargs)
30573057
self.assertEqual(handlr.call_count, 1)
30583058
self.assertEqual(handlr.return_value, response)
@@ -3190,15 +3190,15 @@ def test_add_func_with_id(self):
31903190
"""
31913191
entity = entities.Host(self.cfg, id=1)
31923192
func_param_dict = {entity.add_ansible_role: 'ansible_role_id'}
3193-
for func in func_param_dict:
3193+
for func, param in func_param_dict.items():
31943194
self.assertEqual(inspect.getfullargspec(func), EXPECTED_ARGSPEC)
3195-
kwargs = {'kwarg': gen_integer(), 'data': {func_param_dict[func]: gen_integer()}}
3195+
kwargs = {'kwarg': gen_integer(), 'data': {param: gen_integer()}}
31963196
with mock.patch.object(entities, '_handle_response') as handlr:
31973197
with mock.patch.object(client, 'put') as client_request:
31983198
response = func(**kwargs)
31993199
self.assertEqual(client_request.call_count, 1)
32003200
self.assertEqual(len(client_request.call_args[0]), 1)
3201-
self.assertNotIn(func_param_dict[func], client_request.call_args[1]['data'])
3201+
self.assertNotIn(param, client_request.call_args[1]['data'])
32023202
self.assertEqual(client_request.call_args[1], kwargs)
32033203
self.assertEqual(handlr.call_count, 1)
32043204
self.assertEqual(handlr.return_value, response)
@@ -3220,15 +3220,15 @@ def test_delete_func_with_id(self):
32203220
entity.delete_puppetclass: 'puppetclass_id',
32213221
entity.remove_ansible_role: 'ansible_role_id',
32223222
}
3223-
for func in func_param_dict:
3223+
for func, param in func_param_dict.items():
32243224
self.assertEqual(inspect.getfullargspec(func), EXPECTED_ARGSPEC)
3225-
kwargs = {'kwarg': gen_integer(), 'data': {func_param_dict[func]: gen_integer()}}
3225+
kwargs = {'kwarg': gen_integer(), 'data': {param: gen_integer()}}
32263226
with mock.patch.object(entities, '_handle_response') as handlr:
32273227
with mock.patch.object(client, 'delete') as client_request:
32283228
response = func(**kwargs)
32293229
self.assertEqual(client_request.call_count, 1)
32303230
self.assertEqual(len(client_request.call_args[0]), 1)
3231-
self.assertNotIn(func_param_dict[func], client_request.call_args[1]['data'])
3231+
self.assertNotIn(param, client_request.call_args[1]['data'])
32323232
self.assertEqual(client_request.call_args[1], kwargs)
32333233
self.assertEqual(handlr.call_count, 1)
32343234
self.assertEqual(handlr.return_value, response)

0 commit comments

Comments
 (0)