Skip to content

Commit cfe39fb

Browse files
committed
Linting fixes.
1 parent b1cfd78 commit cfe39fb

File tree

15 files changed

+48
-36
lines changed

15 files changed

+48
-36
lines changed

c8y_api/model/_base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def __len__(self):
9191
# if self.__dict__['_property_on_update']:
9292
# self.__dict__['_property_on_update']()
9393

94-
def insert(self, i, value):
95-
self.__dict__['_property_items'].insert(i, value)
94+
def insert(self, index, value):
95+
self.__dict__['_property_items'].insert(index, value)
9696
if self.__dict__['_property_on_update']:
9797
self.__dict__['_property_on_update']()
9898

@@ -123,7 +123,7 @@ def _repr(self, *names) -> str:
123123
'(',
124124
', '.join(filter(lambda x: x is not None,
125125
[
126-
f'{n}={self.__getattribute__(n)}' if self.__getattribute__(n) else None
126+
f'{n}={getattr(self, n)}' if getattr(self, n) else None
127127
for n in ['id', *names]
128128
])),
129129
')'])
@@ -353,7 +353,7 @@ def _delete(self, **params):
353353
self._assert_id()
354354
self.c8y.delete(self._build_object_path(), params=params)
355355

356-
def delete(self, **_):
356+
def delete(self, **_) -> None:
357357
"""Delete the object within the database."""
358358
self._delete()
359359

@@ -719,7 +719,7 @@ def _apply_to(self, jsonify_func, model: dict|Any, *object_ids):
719719
self.c8y.put(self.resource + '/' + str(object_id), model_json, accept=None)
720720

721721
# this one should be ok for all implementations, hence we define it here
722-
def delete(self, *objects: str):
722+
def delete(self, *objects: str) -> None:
723723
""" Delete one or more objects within the database.
724724
725725
The objects can be specified as instances of a database object

c8y_api/model/_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ class _StringUtil(object):
1414

1515
@staticmethod
1616
def concat(*strings:Union[str, None]):
17+
"""Concatenate non-None strings."""
1718
return ''.join(x for x in strings if x)
1819

1920
@staticmethod
2021
def concat_with(sep: str, *strings:Union[str, None]):
22+
"""Concatenate non-None strings with separator."""
2123
return sep.join(x for x in strings if x)
2224

2325
@staticmethod

c8y_api/model/administration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def update(self) -> InventoryRole:
179179
"""
180180
return super()._update()
181181

182-
def delete(self):
182+
def delete(self, **_) -> None:
183183
"""Delete the role within the database."""
184184
super()._delete()
185185

@@ -291,7 +291,7 @@ def update(self) -> GlobalRole:
291291
"""
292292
return super()._update()
293293

294-
def delete(self):
294+
def delete(self, **_) -> None:
295295
"""Delete the GlobalRole within the database."""
296296
super()._delete()
297297

@@ -594,7 +594,7 @@ def update(self) -> User:
594594
result_json = self.c8y.put(self._build_user_path(), self.to_diff_json(), accept=self._accept)
595595
return self.from_json(result_json)
596596

597-
def delete(self):
597+
def delete(self, **_) -> None:
598598
"""Delete the User within the database."""
599599
self._delete()
600600

@@ -895,7 +895,7 @@ def verify_totp(self, code: str):
895895
try:
896896
self.c8y.post(f'{self._resource}/totpSecret/verify', {'code': code})
897897
except AccessDeniedError as ex:
898-
raise ValueError(ex.message)
898+
raise ValueError(ex.message) from ex
899899

900900
def is_valid_totp(self, code: str) -> bool:
901901
"""Verify a TFA/TOTP token.

c8y_api/model/alarms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def apply_to(self, other_id: str) -> Alarm:
197197
"""
198198
return super()._apply_to(other_id)
199199

200-
def delete(self):
200+
def delete(self, **_) -> None:
201201
"""Delete this object within the database.
202202
203203
An alarm is identified through its type and source. These fields
@@ -492,7 +492,7 @@ def apply_by(
492492
**kwargs)
493493
self.c8y.put(base_query, alarm.to_full_json(), accept='')
494494

495-
def delete(self, *alarms):
495+
def delete(self, *alarms) -> None:
496496
"""Delete alarm objects within the database.
497497
498498
Note: within Cumulocity alarms are identified by type and source.

c8y_api/model/applications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def update(self) -> Application:
134134
"""
135135
return super()._update()
136136

137-
def delete(self):
137+
def delete(self, **_) -> None:
138138
"""Delete the Application within the database."""
139139
super()._delete()
140140

c8y_api/model/events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def update(self) -> Event:
129129
"""
130130
return super()._update()
131131

132-
def delete(self):
132+
def delete(self, **_) -> None:
133133
"""Delete the Event within the database."""
134134
super()._delete()
135135

@@ -205,7 +205,7 @@ def update_attachment(self, file: str | BinaryIO, content_type: str = None) -> d
205205
return self.c8y.put_file(self._build_attachment_path(), file,
206206
accept='application/json', content_type=content_type)
207207

208-
def delete_attachment(self):
208+
def delete_attachment(self) -> None:
209209
"""Remove the binary attachment."""
210210
super()._assert_c8y()
211211
super()._assert_id()
@@ -543,7 +543,7 @@ def download_attachment(self, event_id: str) -> bytes:
543543
"""
544544
return self.c8y.get_file(self.build_attachment_path(event_id))
545545

546-
def delete_attachment(self, event_id: str):
546+
def delete_attachment(self, event_id: str) -> None:
547547
"""Remove an event's binary attachment.
548548
549549
Args:

c8y_api/model/identity.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def create(self) -> ExternalId:
8181
Identity(self.c8y).create(self.external_id, self.external_type, self.managed_object_id)
8282
return self
8383

84-
def delete(self):
84+
def delete(self, **_) -> None:
8585
""" Remove the external ID from the database.
8686
8787
Returns:
@@ -109,11 +109,6 @@ def get_object(self) -> ManagedObject:
109109
self._assert_c8y()
110110
return Identity(self.c8y).get_object(self.external_id, self.external_type)
111111

112-
def __repr__(self):
113-
return str({'external_id': self.external_id,
114-
'external_type': self.external_type,
115-
'object_id': self.managed_object_id})
116-
117112

118113
class Identity(object):
119114
# the Identity API of C8Y uses inconsistent resource paths and therefore
@@ -151,7 +146,7 @@ def create(self, external_id, external_type, managed_object_id):
151146
path = f'/identity/globalIds/{managed_object_id}/externalIds'
152147
self.c8y.post(path, body_json)
153148

154-
def delete(self, external_id, external_type):
149+
def delete(self, external_id, external_type) -> None:
155150
""" Remove an External ID from the database.
156151
157152
Args:

c8y_api/model/inventory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def _collate_filter_params(
288288
text: str = None,
289289
**kwargs,
290290
) -> dict:
291+
# pylint: disable=too-many-branches
291292
query_key = 'q' if only_devices else 'query'
292293

293294
# if query is directly specified -> use it and ignore everything else
@@ -665,7 +666,7 @@ def get_count( # noqa (changed signature)
665666
page_size=1,
666667
**kwargs))
667668

668-
def delete(self, *devices: Device):
669+
def delete(self, *devices: Device) -> None:
669670
""" Delete one or more devices and the corresponding within the database.
670671
671672
The objects can be specified as instances of a database object
@@ -961,7 +962,7 @@ def unassign_children(self, root_id, *child_ids):
961962
refs = {'references': [ManagedObjectUtil.build_managed_object_reference(i) for i in child_ids]}
962963
self.c8y.delete(self.build_object_path(root_id) + '/childAssets', json=refs)
963964

964-
def delete(self, *groups: DeviceGroup | str):
965+
def delete(self, *groups: DeviceGroup | str) -> None:
965966
"""Delete one or more single device groups within the database.
966967
967968
The child groups (if there are any) are left dangling. This is
@@ -973,7 +974,7 @@ def delete(self, *groups: DeviceGroup | str):
973974
"""
974975
self._delete(False, *groups)
975976

976-
def delete_trees(self, *groups: DeviceGroup | str):
977+
def delete_trees(self, *groups: DeviceGroup | str) -> None:
977978
"""Delete one or more device groups trees within the database.
978979
979980
This is equivalent to using the `cascade=true` parameter in the

c8y_api/model/managedobjects.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from c8y_api.model.administration import User, Users
1010
from c8y_api.model._base import _DictWrapper, SimpleObject, ComplexObject
1111
from c8y_api.model._parser import ComplexObjectParser
12-
from c8y_api.model._util import _DateUtil, _StringUtil
12+
from c8y_api.model._util import _DateUtil
1313

1414

1515
class NamedObject(object):
@@ -433,7 +433,7 @@ def apply_to(self, other_id: str | int) -> ManagedObject:
433433
result.c8y = self.c8y
434434
return result
435435

436-
def delete(self):
436+
def delete(self, **_) -> None:
437437
""" Delete this object within the database.
438438
439439
Note: child additions, assets (and devices) are not implicitly
@@ -443,7 +443,7 @@ def delete(self):
443443
"""
444444
self._delete()
445445

446-
def delete_tree(self):
446+
def delete_tree(self) -> None:
447447
"""Delete this managed object within the database including child.
448448
additions, devices and assets.
449449
This is equivalent to using the `forceCascade` parameter of the
@@ -644,7 +644,7 @@ def reload(self) -> Device:
644644
"""
645645
return self._reload(Device())
646646

647-
def delete(self, with_device_user=False):
647+
def delete(self, with_device_user=False, **_) -> None:
648648
"""Delete this device object within the database.
649649
650650
Note: child additions, assets (and devices) are not implicitly
@@ -661,7 +661,7 @@ def delete(self, with_device_user=False):
661661
else:
662662
self._delete()
663663

664-
def delete_tree(self, with_device_user=False):
664+
def delete_tree(self, with_device_user=False) -> None:
665665
"""Delete this device object within the database including child.
666666
additions, devices and assets.
667667
@@ -794,7 +794,7 @@ def update(self) -> DeviceGroup:
794794
"""
795795
return super()._update()
796796

797-
def delete(self):
797+
def delete(self, **_) -> None:
798798
"""Delete this device group.
799799
800800
The child groups (if there are any) are left dangling. This is
@@ -803,7 +803,7 @@ def delete(self):
803803
"""
804804
self._delete(cascade='false')
805805

806-
def delete_tree(self):
806+
def delete_tree(self) -> None:
807807
"""Delete this device group and its children.
808808
809809
This is equivalent to using the `cascade=true` parameter in the

c8y_api/model/measurements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def update(self) -> Measurement:
249249
"""Not implemented for Measurements."""
250250
raise NotImplementedError('Measurements cannot be updated within Cumulocity.')
251251

252-
def delete(self):
252+
def delete(self, **_) -> None:
253253
"""Delete the Measurement within the database."""
254254
self._delete()
255255

0 commit comments

Comments
 (0)