Skip to content

Commit 87ab734

Browse files
committed
style: make all mutable function arguments "None" and init in function body
1 parent 09c5530 commit 87ab734

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

dataikuapi/dss/macro.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_definition(self):
3333
return self.definition
3434

3535

36-
def run(self, params={}, admin_params={}, wait=True):
36+
def run(self, params=None, admin_params=None, wait=True):
3737
"""
3838
Run the macro from the project
3939
@@ -43,6 +43,10 @@ def run(self, params={}, admin_params={}, wait=True):
4343
:param wait: if True, the call blocks until the run is finished
4444
:returns: a run identifier to use to abort or retrieve results
4545
"""
46+
if params is None:
47+
params = {}
48+
if admin_params is None:
49+
admin_params = {}
4650
return self.client._perform_json(
4751
"POST", "/projects/%s/runnables/%s" % (self.project_key, self.runnable_type),
4852
params={'wait':wait}, body={'params':params, 'adminParams':admin_params})['runId']

dataikuapi/dss/ml.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ def train(self, session_name=None, session_description=None):
12551255
self.wait_train_complete()
12561256
return self.get_trained_models_ids(session_id = train_ret["sessionId"])
12571257

1258-
def ensemble(self, model_ids=[], method=None):
1258+
def ensemble(self, model_ids=None, method=None):
12591259
"""
12601260
Create an ensemble model of a set of models
12611261
@@ -1273,6 +1273,8 @@ def ensemble(self, model_ids=[], method=None):
12731273
:return: A model identifier
12741274
:rtype: string
12751275
"""
1276+
if model_ids is None:
1277+
model_ids = []
12761278
train_ret = self.start_ensembling(model_ids, method)
12771279
self.wait_train_complete()
12781280
return train_ret
@@ -1296,7 +1298,7 @@ def start_train(self, session_name=None, session_description=None):
12961298
"POST", "/projects/%s/models/lab/%s/%s/train" % (self.project_key, self.analysis_id, self.mltask_id), body=session_info)
12971299

12981300

1299-
def start_ensembling(self, model_ids=[], method=None):
1301+
def start_ensembling(self, model_ids=None, method=None):
13001302
"""
13011303
Creates asynchronously a new ensemble models of a set of models.
13021304
@@ -1308,6 +1310,8 @@ def start_ensembling(self, model_ids=[], method=None):
13081310
:return: the model identifier of the ensemble
13091311
:rtype: string
13101312
"""
1313+
if model_ids is None:
1314+
model_ids = []
13111315
ensembling_request = {
13121316
"method" : method,
13131317
"modelsIds" : model_ids

dataikuapi/dss/project.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def delete(self, drop_data=False):
4949
# Project export
5050
########################################################
5151

52-
def get_export_stream(self, options = {}):
52+
def get_export_stream(self, options=None):
5353
"""
5454
Return a stream of the exported project
5555
You need to close the stream after download. Failure to do so will result in the DSSClient becoming unusable.
@@ -70,15 +70,19 @@ def get_export_stream(self, options = {}):
7070
:returns: a file-like obbject that is a stream of the export archive
7171
:rtype: file-like
7272
"""
73+
if options is None:
74+
options = {}
7375
return self.client._perform_raw(
7476
"POST", "/projects/%s/export" % self.project_key, body=options).raw
7577

76-
def export_to_file(self, path, options={}):
78+
def export_to_file(self, path, options=None):
7779
"""
7880
Export the project to a file
7981
8082
:param str path: the path of the file in which the exported project should be saved
8183
"""
84+
if options is None:
85+
options = {}
8286
with open(path, 'wb') as f:
8387
export_stream = self.client._perform_raw(
8488
"POST", "/projects/%s/export" % self.project_key, body=options)
@@ -98,7 +102,7 @@ def duplicate(self, target_project_key,
98102
export_saved_models=True,
99103
export_git_repository=True,
100104
export_insights_data=True,
101-
remapping={},
105+
remapping=None,
102106
target_project_folder=None):
103107
"""
104108
Duplicate the project
@@ -116,7 +120,8 @@ def duplicate(self, target_project_key,
116120
:returns: A dict containing the original and duplicated project's keys
117121
:rtype: :class:`ProjectDuplicateResult`
118122
"""
119-
123+
if remapping is None:
124+
remapping = {}
120125
obj = {
121126
"targetProjectName": target_project_name,
122127
"targetProjectKey": target_project_key,
@@ -211,7 +216,7 @@ def get_dataset(self, dataset_name):
211216
return DSSDataset(self.client, self.project_key, dataset_name)
212217

213218
def create_dataset(self, dataset_name, type,
214-
params={}, formatType=None, formatParams={}):
219+
params=None, formatType=None, formatParams=None):
215220
"""
216221
Create a new dataset in the project, and return a handle to interact with it.
217222
@@ -232,6 +237,10 @@ def create_dataset(self, dataset_name, type,
232237
Returns:
233238
A :class:`dataikuapi.dss.dataset.DSSDataset` dataset handle
234239
"""
240+
if params is None:
241+
params = {}
242+
if formatParams is None:
243+
formatParams = {}
235244
obj = {
236245
"name" : dataset_name,
237246
"projectKey" : self.project_key,
@@ -676,7 +685,7 @@ def get_scenario(self, scenario_id):
676685
"""
677686
return DSSScenario(self.client, self.project_key, scenario_id)
678687

679-
def create_scenario(self, scenario_name, type, definition={'params': {}}):
688+
def create_scenario(self, scenario_name, type, definition=None):
680689
"""
681690
Create a new scenario in the project, and return a handle to interact with it
682691
@@ -688,6 +697,8 @@ def create_scenario(self, scenario_name, type, definition={'params': {}}):
688697
689698
:returns: a :class:`.scenario.DSSScenario` handle to interact with the newly-created scenario
690699
"""
700+
if definition is None:
701+
definition = {'params': {}}
691702
definition['type'] = type
692703
definition['name'] = scenario_name
693704
scenario_id = self.client._perform_json("POST", "/projects/%s/scenarios/" % self.project_key,
@@ -790,12 +801,14 @@ def get_tags(self):
790801
"""
791802
return self.client._perform_json("GET", "/projects/%s/tags" % self.project_key)
792803

793-
def set_tags(self, tags={}):
804+
def set_tags(self, tags=None):
794805
"""
795806
Set the tags of this project.
796807
@param obj: must be a modified version of the object returned by list_tags
797808
"""
798-
return self.client._perform_empty("PUT", "/projects/%s/tags" % self.project_key, body = tags)
809+
if tags is None:
810+
tags = {}
811+
return self.client._perform_empty("PUT", "/projects/%s/tags" % self.project_key, body=tags)
799812

800813

801814
########################################################

dataikuapi/dss/scenario.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ def abort(self):
2020
return self.client._perform_json(
2121
"POST", "/projects/%s/scenarios/%s/abort" % (self.project_key, self.id))
2222

23-
def run(self, params={}):
23+
def run(self, params=None):
2424
"""
2525
Requests a run of the scenario, which will start after a few seconds.
2626
2727
:params dict params: additional parameters that will be passed to the scenario through trigger params
2828
"""
29+
if params is None:
30+
params = {}
2931
trigger_fire = self.client._perform_json(
3032
"POST", "/projects/%s/scenarios/%s/run" % (self.project_key, self.id), body=params)
3133
return DSSTriggerFire(self, trigger_fire)
@@ -47,7 +49,7 @@ def get_trigger_fire(self, trigger_id, trigger_run_id):
4749
})
4850
return DSSTriggerFire(self, trigger_fire)
4951

50-
def run_and_wait(self, params={}, no_fail=False):
52+
def run_and_wait(self, params=None, no_fail=False):
5153
"""
5254
Requests a run of the scenario, which will start after a few seconds. Wait the end of the run to complete.
5355
@@ -57,6 +59,8 @@ def run_and_wait(self, params={}, no_fail=False):
5759
Returns:
5860
A :class:`dataikuapi.dss.admin.DSSScenarioRun` run handle
5961
"""
62+
if params is None:
63+
params = {}
6064
trigger_fire = self.run(params)
6165
scenario_run = trigger_fire.wait_for_scenario_run(no_fail)
6266
waiter = DSSScenarioRunWaiter(scenario_run, trigger_fire)

dataikuapi/dssclient.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def get_plugin(self, plugin_id):
245245
# SQL queries
246246
########################################################
247247

248-
def sql_query(self, query, connection=None, database=None, dataset_full_name=None, pre_queries=None, post_queries=None, type='sql', extra_conf={}, script_steps=None, script_input_schema=None, script_output_schema=None, script_report_location=None, read_timestamp_without_timezone_as_string=True, read_date_as_string=False):
248+
def sql_query(self, query, connection=None, database=None, dataset_full_name=None, pre_queries=None, post_queries=None, type='sql', extra_conf=None, script_steps=None, script_input_schema=None, script_output_schema=None, script_report_location=None, read_timestamp_without_timezone_as_string=True, read_date_as_string=False):
249249
"""
250250
Initiate a SQL, Hive or Impala query and get a handle to retrieve the results of the query.
251251
Internally, the query is run by DSS. The database to run the query on is specified either by
@@ -262,6 +262,8 @@ def sql_query(self, query, connection=None, database=None, dataset_full_name=Non
262262
263263
:returns: A :class:`dataikuapi.dss.sqlquery.DSSSQLQuery` query handle
264264
"""
265+
if extra_conf is None:
266+
extra_conf = {}
265267
return DSSSQLQuery(self, query, connection, database, dataset_full_name, pre_queries, post_queries, type, extra_conf, script_steps, script_input_schema, script_output_schema, script_report_location, read_timestamp_without_timezone_as_string, read_date_as_string)
266268

267269
########################################################
@@ -290,7 +292,7 @@ def get_user(self, login):
290292
"""
291293
return DSSUser(self, login)
292294

293-
def create_user(self, login, password, display_name='', source_type='LOCAL', groups=[], profile='DATA_SCIENTIST'):
295+
def create_user(self, login, password, display_name='', source_type='LOCAL', groups=None, profile='DATA_SCIENTIST'):
294296
"""
295297
Create a user, and return a handle to interact with it
296298
@@ -305,6 +307,8 @@ def create_user(self, login, password, display_name='', source_type='LOCAL', gro
305307
306308
:return: A :class:`dataikuapi.dss.admin.DSSUser` user handle
307309
"""
310+
if groups is None:
311+
groups = []
308312
resp = self._perform_text(
309313
"POST", "/admin/users/", body={
310314
"login" : login,
@@ -386,7 +390,7 @@ def get_connection(self, name):
386390
"""
387391
return DSSConnection(self, name)
388392

389-
def create_connection(self, name, type, params={}, usable_by='ALL', allowed_groups=[]):
393+
def create_connection(self, name, type, params=None, usable_by='ALL', allowed_groups=None):
390394
"""
391395
Create a connection, and return a handle to interact with it
392396
@@ -402,6 +406,10 @@ def create_connection(self, name, type, params={}, usable_by='ALL', allowed_grou
402406
403407
:returns: A :class:`dataikuapi.dss.admin.DSSConnection` connection handle
404408
"""
409+
if params is None:
410+
params = {}
411+
if allowed_groups is None:
412+
allowed_groups = []
405413
resp = self._perform_text(
406414
"POST", "/admin/connections/", body={
407415
"name" : name,
@@ -659,13 +667,15 @@ def get_log(self, name):
659667
return self._perform_json(
660668
"GET", "/admin/logs/%s" % name)
661669

662-
def log_custom_audit(self, custom_type, custom_params={}):
670+
def log_custom_audit(self, custom_type, custom_params=None):
663671
"""
664672
Log a custom entry to the audit trail
665673
666674
:param str custom_type value for customMsgType in audit trail item
667675
:param dict custom_params value for customMsgParams in audit trail item
668676
"""
677+
if custom_params is None:
678+
custom_params = {}
669679
return self._perform_empty("POST",
670680
"/admin/audit/custom/%s" % custom_type,
671681
body = custom_params)
@@ -780,10 +790,12 @@ def get_apideployer(self):
780790
# Data Catalog
781791
########################################################
782792

783-
def catalog_index_connections(self, connection_names=[], all_connections=False, indexing_mode="FULL"):
793+
def catalog_index_connections(self, connection_names=None, all_connections=False, indexing_mode="FULL"):
784794
"""
785795
Triggers an indexing of multiple connections in the data catalog
786796
"""
797+
if connection_names is None:
798+
connection_names = []
787799
return self._perform_json("POST", "/catalog/index", body={
788800
"connectionNames": connection_names,
789801
"indexAllConnections": all_connections,
@@ -939,7 +951,7 @@ def __init__(self, client, import_id):
939951
self.client = client
940952
self.import_id = import_id
941953

942-
def execute(self, settings = {}):
954+
def execute(self, settings=None):
943955
"""
944956
Executes the import with provided settings.
945957
@@ -966,7 +978,7 @@ def execute(self, settings = {}):
966978
@warning: You must check the 'success' flag
967979
"""
968980
# Empty JSON dicts can't be parsed properly
969-
if settings == {}:
970-
settings["_"] = "_"
981+
if settings is None:
982+
settings = {"_": "_"}
971983
return self.client._perform_json("POST", "/projects/import/%s/process" % (self.import_id),
972984
body = settings)

0 commit comments

Comments
 (0)