Skip to content

Commit 1286eac

Browse files
DaveSawyerlukaszsocha2
authored andcommitted
fix!: Changed some functions signarure to fix liskov substitution violations
BREAKING CHANGE: Changed function signatures: - get_url() in base_endpoint.py - copy() in 'base_item.py' 'file.py' - create_shared_link() in 'base_item.py', 'item.py' - get_shared_link() in 'base_item.py', 'item.py' - remove_shared_link() in 'base_item.py', 'item.py' - get() in base_object.py, 'item.py' - update_info() in base_object.py, collaboration.py, 'item.py', metadata_template.py - delete() in base_object.py, folder.py, 'item.py', user.py Closes: SDK-1904
1 parent e8abbb5 commit 1286eac

29 files changed

+84
-80
lines changed

boxsdk/object/base_endpoint.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ def translator(self) -> 'Translator':
3434
"""
3535
return self._session.translator
3636

37-
def get_url(self, endpoint: str, *args: Any) -> str:
37+
def get_url(self, *args: Any) -> str:
3838
"""
3939
Return the URL used to access the endpoint.
4040
41-
:param endpoint:
42-
The name of the endpoint.
4341
:param args:
44-
Additional parts of the endpoint URL.
42+
Parts of the endpoint URL.
4543
"""
46-
# pylint:disable=no-self-use
47-
return self._session.get_url(endpoint, *args)
44+
return self._session.get_url(*args)
4845

4946
def clone(self, session: 'Session' = None) -> 'BaseEndpoint':
5047
"""

boxsdk/object/base_item.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class BaseItem(BaseObject):
1616

1717
@api_call
18-
def copy(self, parent_folder: 'Folder', name: str = None) -> 'BaseItem':
18+
def copy(self, *, parent_folder: 'Folder', name: str = None, **_kwargs) -> 'BaseItem':
1919
"""Copy the item to the given folder.
2020
2121
:param parent_folder:
@@ -52,7 +52,7 @@ def move(self, parent_folder: 'Folder', name: str = None) -> 'BaseItem':
5252
}
5353
if name is not None:
5454
data['name'] = name
55-
return self.update_info(data)
55+
return self.update_info(data=data)
5656

5757
@api_call
5858
def rename(self, name: str) -> 'BaseItem':
@@ -65,7 +65,7 @@ def rename(self, name: str) -> 'BaseItem':
6565
data = {
6666
'name': name,
6767
}
68-
return self.update_info(data)
68+
return self.update_info(data=data)
6969

7070
@api_call
7171
def create_shared_link(self, **kwargs: Any) -> Any:
@@ -102,7 +102,7 @@ def create_shared_link(self, **kwargs: Any) -> Any:
102102
data = {'shared_link': shared_link}
103103
update_info_kwargs = {'etag': kwargs.get('etag')} if kwargs.get('etag') is not None else {}
104104

105-
return self.update_info(data, **update_info_kwargs)
105+
return self.update_info(data=data, **update_info_kwargs)
106106

107107
@api_call
108108
def get_shared_link(self, **kwargs: Any) -> str:
@@ -131,7 +131,7 @@ def remove_shared_link(self, **kwargs: Any) -> bool:
131131
data = {'shared_link': None}
132132
update_info_kwargs = {'etag': kwargs.get('etag')} if kwargs.get('etag') is not None else {}
133133

134-
item = self.update_info(data, **update_info_kwargs)
134+
item = self.update_info(data=data, **update_info_kwargs)
135135
return item.shared_link is None # pylint:disable=no-member
136136

137137
@api_call
@@ -149,7 +149,7 @@ def add_to_collection(self, collection: 'Collection') -> 'BaseItem':
149149
data = {
150150
'collections': collections
151151
}
152-
return self.update_info(data)
152+
return self.update_info(data=data)
153153

154154
@api_call
155155
def remove_from_collection(self, collection: 'Collection') -> 'BaseItem':
@@ -166,7 +166,7 @@ def remove_from_collection(self, collection: 'Collection') -> 'BaseItem':
166166
data = {
167167
'collections': updated_collections
168168
}
169-
return self.update_info(data)
169+
return self.update_info(data=data)
170170

171171
@staticmethod
172172
def validate_item_id(item_id: Union[str, int]) -> None:

boxsdk/object/base_object.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
22

33
import json
4-
from typing import TYPE_CHECKING, Any, Iterable, Optional
4+
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union, List
55

66
from .base_endpoint import BaseEndpoint
77
from .base_api_json_object import BaseAPIJSONObject
@@ -40,7 +40,6 @@ def get_url(self, *args: Any) -> str:
4040
Base class override.
4141
Return the given object's URL, appending any optional parts as specified by args.
4242
"""
43-
# pylint:disable=arguments-differ
4443
return super().get_url(f'{self._item_type}s', self._object_id, *args)
4544

4645
def get_type_url(self) -> str:
@@ -57,7 +56,7 @@ def object_id(self) -> str:
5756
return self._object_id
5857

5958
@api_call
60-
def get(self, fields: Iterable[str] = None, headers: dict = None) -> Any:
59+
def get(self, *, fields: Iterable[str] = None, headers: dict = None, **_kwargs) -> Any:
6160
"""
6261
Get information about the object, specified by fields. If fields is None, return the default fields.
6362
@@ -79,7 +78,8 @@ def get(self, fields: Iterable[str] = None, headers: dict = None) -> Any:
7978
@api_call
8079
def update_info(
8180
self,
82-
data: dict,
81+
*,
82+
data: Union[dict, List[dict]],
8383
params: Optional[dict] = None,
8484
headers: Optional[dict] = None,
8585
**kwargs: Any
@@ -109,19 +109,18 @@ def update_info(
109109
Construct the new object with all the default attributes that are
110110
returned from the endpoint.
111111
"""
112-
# pylint:disable=no-else-return
113112
url = self.get_url()
114113
box_response = self._session.put(url, data=json.dumps(data), params=params, headers=headers, **kwargs)
115114
if 'expect_json_response' in kwargs and not kwargs['expect_json_response']:
116115
return box_response.ok
117-
else:
118-
return self.translator.translate(
119-
session=self._session,
120-
response_object=box_response.json(),
121-
)
116+
117+
return self.translator.translate(
118+
session=self._session,
119+
response_object=box_response.json(),
120+
)
122121

123122
@api_call
124-
def delete(self, params: Optional[dict] = None, headers: Optional[dict] = None) -> bool:
123+
def delete(self, *, params: Optional[dict] = None, headers: Optional[dict] = None, **_kwargs) -> bool:
125124
""" Delete the object.
126125
127126
:param params:
@@ -134,8 +133,7 @@ def delete(self, params: Optional[dict] = None, headers: Optional[dict] = None)
134133
:class:`BoxAPIException` in case of unexpected errors.
135134
"""
136135
url = self.get_url()
137-
# ??? There's a question about why params forces a default to {}, while headers doesn't. Looking for
138-
# confirmation that the below is correct.
136+
139137
box_response = self._session.delete(url, expect_json_response=False, params=params or {}, headers=headers)
140138
return box_response.ok
141139

boxsdk/object/collaboration.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding: utf-8
2-
from typing import Optional
2+
from typing import Optional, Any
33

44
from boxsdk.object.base_object import BaseObject
55
from boxsdk.util.text_enum import TextEnum
@@ -34,8 +34,10 @@ class Collaboration(BaseObject):
3434
@api_call
3535
def update_info(
3636
self,
37+
*,
3738
role: Optional[CollaborationRole] = None,
38-
status: Optional[CollaborationStatus] = None
39+
status: Optional[CollaborationStatus] = None,
40+
**kwargs: Any
3941
) -> 'BaseObject':
4042
"""Edit an existing collaboration on Box
4143
@@ -56,9 +58,9 @@ def update_info(
5658
if status:
5759
data['status'] = status
5860
if role == CollaborationRole.OWNER:
59-
return super().update_info(data=data, expect_json_response=False)
61+
return super().update_info(data=data, expect_json_response=False, **kwargs)
6062

61-
return super().update_info(data=data)
63+
return super().update_info(data=data, **kwargs)
6264

6365
@api_call
6466
def accept(self) -> 'BaseObject':

boxsdk/object/comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ def edit(self, message: str) -> 'Comment':
4747
The content of the reply comment.
4848
"""
4949
data = self.construct_params_from_message(message)
50-
return self.update_info(data)
50+
return self.update_info(data=data)

boxsdk/object/events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Events(BaseEndpoint):
6060

6161
def get_url(self, *args: Any) -> str:
6262
"""Base class override."""
63-
# pylint:disable=arguments-differ
6463
return super().get_url('events', *args)
6564

6665
@api_call

boxsdk/object/file.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def lock(self, prevent_download: bool = False, expire_time: Optional[str] = None
344344
}
345345
if expire_time is not None:
346346
data['lock']['expires_at'] = expire_time
347-
return self.update_info(data)
347+
return self.update_info(data=data)
348348

349349
@api_call
350350
def unlock(self) -> 'File':
@@ -355,7 +355,7 @@ def unlock(self) -> 'File':
355355
A new :class:`File` instance reflecting that the file has been unlocked.
356356
"""
357357
data = {'lock': None}
358-
return self.update_info(data)
358+
return self.update_info(data=data)
359359

360360
@api_call
361361
def get_shared_link_download_url(
@@ -681,7 +681,14 @@ def get_thumbnail_representation(self, dimensions: str, extension: str = 'png')
681681
return b''
682682

683683
@api_call
684-
def copy(self, parent_folder: 'Folder', name: Optional[str] = None, file_version: 'FileVersion' = None) -> 'File':
684+
def copy(
685+
self,
686+
*,
687+
parent_folder: 'Folder',
688+
name: Optional[str] = None,
689+
file_version: 'FileVersion' = None,
690+
**_kwargs
691+
) -> 'File':
685692
# pylint: disable=arguments-differ
686693
"""Copy the item to the given folder.
687694
@@ -694,6 +701,7 @@ def copy(self, parent_folder: 'Folder', name: Optional[str] = None, file_version
694701
:returns:
695702
The copy of the file
696703
"""
704+
# pylint: disable=arguments-differ
697705
url = self.get_url('copy')
698706
data = {
699707
'parent': {'id': parent_folder.object_id}

boxsdk/object/folder.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,13 @@ def create_web_link(
503503
)
504504

505505
@api_call
506-
def delete(self, recursive: bool = True, etag: Optional[str] = None) -> bool:
506+
def delete(
507+
self,
508+
*,
509+
recursive: bool = True,
510+
etag: Optional[str] = None,
511+
**kwargs
512+
) -> bool:
507513
"""Base class override. Delete the folder.
508514
509515
:param recursive:
@@ -515,7 +521,7 @@ def delete(self, recursive: bool = True, etag: Optional[str] = None) -> bool:
515521
:raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the folder.
516522
"""
517523
# pylint:disable=arguments-differ,arguments-renamed
518-
return super().delete({'recursive': recursive}, etag)
524+
return super().delete(params={'recursive': recursive}, etag=etag, **kwargs)
519525

520526
@api_call
521527
def get_metadata_cascade_policies(

boxsdk/object/item.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _preflight_check(
9999
return response_json.get('upload_url', None)
100100

101101
@api_call
102-
def update_info(self, data: dict, etag: Optional[str] = None) -> 'Item':
102+
def update_info(self, *, data: dict, etag: Optional[str] = None, **kwargs: Any) -> 'Item':
103103
"""
104104
Baseclass override.
105105
:param data:
@@ -120,10 +120,10 @@ def update_info(self, data: dict, etag: Optional[str] = None) -> 'Item':
120120
# pylint:disable=arguments-differ
121121
self.validate_item_id(self._object_id)
122122
headers = {'If-Match': etag} if etag is not None else None
123-
return super().update_info(data, headers=headers)
123+
return super().update_info(data=data, headers=headers, **kwargs)
124124

125125
@api_call
126-
def get(self, fields: Iterable[str] = None, etag: Optional[str] = None) -> 'Item':
126+
def get(self, *, fields: Iterable[str] = None, etag: Optional[str] = None, **kwargs) -> 'Item':
127127
"""
128128
Base class override.
129129
@@ -138,11 +138,12 @@ def get(self, fields: Iterable[str] = None, etag: Optional[str] = None) -> 'Item
138138
# pylint:disable=arguments-differ,arguments-renamed
139139
self.validate_item_id(self._object_id)
140140
headers = {'If-None-Match': etag} if etag is not None else None
141-
return super().get(fields=fields, headers=headers)
141+
return super().get(fields=fields, headers=headers, **kwargs)
142142

143143
@api_call
144144
def create_shared_link(
145145
self,
146+
*,
146147
access: Optional[str] = None,
147148
etag: Optional[str] = None,
148149
unshared_at: Optional[str] = SDK_VALUE_NOT_SET,
@@ -198,6 +199,7 @@ def create_shared_link(
198199
@api_call
199200
def get_shared_link(
200201
self,
202+
*,
201203
access: Optional[str] = None,
202204
etag: Optional[str] = None,
203205
unshared_at: Optional[str] = SDK_VALUE_NOT_SET,
@@ -248,7 +250,7 @@ def get_shared_link(
248250
)
249251

250252
@api_call
251-
def remove_shared_link(self, etag: Optional[str] = None, **kwargs: Any) -> bool:
253+
def remove_shared_link(self, *, etag: Optional[str] = None, **kwargs: Any) -> bool:
252254
"""
253255
Baseclass override.
254256
@@ -264,7 +266,7 @@ def remove_shared_link(self, etag: Optional[str] = None, **kwargs: Any) -> bool:
264266
return super().remove_shared_link(etag=etag)
265267

266268
@api_call
267-
def delete(self, params: dict = None, etag: Optional[str] = None) -> bool:
269+
def delete(self, *, params: dict = None, etag: Optional[str] = None, **kwargs) -> bool:
268270
"""Delete the item.
269271
270272
:param params:
@@ -278,7 +280,7 @@ def delete(self, params: dict = None, etag: Optional[str] = None) -> bool:
278280
# pylint:disable=arguments-differ,arguments-renamed
279281
self.validate_item_id(self._object_id)
280282
headers = {'If-Match': etag} if etag is not None else None
281-
return super().delete(params, headers)
283+
return super().delete(params=params, headers=headers, **kwargs)
282284

283285
def metadata(self, scope: str = 'global', template: str = 'properties') -> Metadata:
284286
"""

boxsdk/object/metadata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def __init__(self, session: 'Session', box_object: 'BaseObject', scope: str, tem
103103

104104
def get_url(self, *args: Any) -> str:
105105
""" Base class override. """
106-
# pylint:disable=arguments-differ
107106
return self._object.get_url('metadata', self._scope, self._template)
108107

109108
@staticmethod

0 commit comments

Comments
 (0)