Skip to content

Commit

Permalink
[Development] Fix Function Signatures That Use Mutable Objects As Def…
Browse files Browse the repository at this point in the history
…aults (#5637)
  • Loading branch information
quaark committed May 27, 2024
1 parent 76e658b commit cc385be
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion mlrun/datastore/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def get_spark_options(self, key_column=None, timestamp_key=None, overwrite=True)
# options used in spark.read.load(**options)
raise NotImplementedError()

def prepare_spark_df(self, df, key_columns, timestamp_key=None, spark_options={}):
def prepare_spark_df(self, df, key_columns, timestamp_key=None, spark_options=None):
return df

def get_dask_options(self):
Expand Down
3 changes: 2 additions & 1 deletion mlrun/frameworks/parallel_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def compare_db_runs(
iter=False,
start_time_from: datetime = None,
hide_identical: bool = True,
exclude: list = [],
exclude: list = None,
show=None,
colorscale: str = "Blues",
filename=None,
Expand Down Expand Up @@ -332,6 +332,7 @@ def compare_db_runs(
**query_args,
)

exclude = exclude or []
runs_df = _runs_list_to_df(runs_list)
plot_as_html = gen_pcp_plot(
runs_df,
Expand Down
8 changes: 4 additions & 4 deletions mlrun/projects/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def my_pipe(url=""):
class BuildStatus:
"""returned status from build operation"""

def __init__(self, ready, outputs={}, function=None):
def __init__(self, ready, outputs=None, function=None):
self.ready = ready
self.outputs = outputs
self.outputs = outputs or {}
self.function = function

def after(self, step):
Expand Down Expand Up @@ -343,9 +343,9 @@ def build_function(
class DeployStatus:
"""returned status from deploy operation"""

def __init__(self, state, outputs={}, function=None):
def __init__(self, state, outputs=None, function=None):
self.state = state
self.outputs = outputs
self.outputs = outputs or {}
self.function = function

def after(self, step):
Expand Down
6 changes: 4 additions & 2 deletions mlrun/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4017,8 +4017,8 @@ def _run_authenticated_git_action(
self,
action: Callable,
remote: str,
args: list = [],
kwargs: dict = {},
args: list = None,
kwargs: dict = None,
secrets: Union[SecretsStore, dict] = None,
):
"""Run an arbitrary Git routine while the remote is enriched with secrets
Expand All @@ -4038,6 +4038,8 @@ def _run_authenticated_git_action(
try:
if is_remote_enriched:
self.spec.repo.remotes[remote].set_url(enriched_remote, clean_remote)
args = args or []
kwargs = kwargs or {}
action(*args, **kwargs)
except RuntimeError as e:
raise mlrun.errors.MLRunRuntimeError(
Expand Down
3 changes: 2 additions & 1 deletion mlrun/serving/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def v2_serving_handler(context, event, get_body=False):


def create_graph_server(
parameters={},
parameters=None,
load_mode=None,
graph=None,
verbose=False,
Expand All @@ -403,6 +403,7 @@ def create_graph_server(
server.graph.add_route("my", class_name=MyModelClass, model_path="{path}", z=100)
print(server.test("/v2/models/my/infer", testdata))
"""
parameters = parameters or {}
server = GraphServer(graph, parameters, load_mode, verbose=verbose, **kwargs)
server.set_current_function(
current_function or os.environ.get("SERVING_CURRENT_FUNCTION", "")
Expand Down
3 changes: 2 additions & 1 deletion mlrun/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def get_function(function, namespace):


def get_handler_extended(
handler_path: str, context=None, class_args: dict = {}, namespaces=None
handler_path: str, context=None, class_args: dict = None, namespaces=None
):
"""get function handler from [class_name::]handler string
Expand All @@ -1116,6 +1116,7 @@ def get_handler_extended(
:param namespaces: one or list of namespaces/modules to search the handler in
:return: function handler (callable)
"""
class_args = class_args or {}
if "::" not in handler_path:
return get_function(handler_path, namespaces)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extend-select = [
"N806", # lowercase variable names
"N816", # snake_case for global variable names
"N999", # snake_case for module names
"B006", # mutable default arguments
]
exclude = ["*.ipynb"]
explicit-preview-rules = true
Expand Down
2 changes: 1 addition & 1 deletion server/api/utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def make_kaniko_pod(
runtime_spec=None,
registry=None,
extra_args="",
extra_labels={},
extra_labels=None,
project_secrets=None,
):
extra_runtime_spec = {}
Expand Down
6 changes: 4 additions & 2 deletions tests/api/api/feature_store/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def _assert_diff_as_expected_except_for_specific_metadata(
expected_object,
actual_object,
allowed_metadata_fields,
expected_diff={},
allowed_spec_fields=[],
expected_diff=None,
allowed_spec_fields=None,
):
expected_diff = expected_diff or {}
allowed_spec_fields = allowed_spec_fields or []
exclude_paths = []
for field in allowed_metadata_fields:
exclude_paths.append(f"root['metadata']['{field}']")
Expand Down
2 changes: 1 addition & 1 deletion tests/api/api/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _mock_run_pipeline(
experiment_id,
job_name,
pipeline_package_path=None,
params={},
params=None,
pipeline_id=None,
version_id=None,
):
Expand Down
6 changes: 4 additions & 2 deletions tests/api/runtimes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,15 @@ def _assert_pod_creation_config(
expected_limits=None,
expected_requests=None,
expected_code=None,
expected_env={},
expected_env=None,
expected_node_name=None,
expected_node_selector=None,
expected_affinity=None,
expected_priority_class_name=None,
assert_create_pod_called=True,
assert_namespace_env_variable=True,
expected_labels=None,
expected_env_from_secrets={},
expected_env_from_secrets=None,
expected_args=None,
):
if assert_create_pod_called:
Expand All @@ -749,6 +749,8 @@ def _assert_pod_creation_config(

expected_code_found = False

expected_env = expected_env or {}
expected_env_from_secrets = expected_env_from_secrets or {}
if assert_namespace_env_variable:
expected_env["MLRUN_NAMESPACE"] = self.namespace

Expand Down
2 changes: 1 addition & 1 deletion tests/api/runtimes/test_nuclio.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _assert_deploy_called_basic_config(
self,
expected_class="remote",
call_count=1,
expected_params=[],
expected_params=None,
expected_labels=None,
expected_env_from_secrets=None,
expected_service_account=None,
Expand Down
4 changes: 2 additions & 2 deletions tests/serving/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
class Echo:
"""example class"""

def __init__(self, context, name=None, data={}):
def __init__(self, context, name=None, data=None):
self.context = context
self.name = name
self.data = data
self.data = data or {}

def do(self, x):
self.context.logger.info("test text")
Expand Down
4 changes: 2 additions & 2 deletions tests/serving/test_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def generate_test_routes_classification(model_class):
)


def generate_spec(graph, mode="sync", params={}):
def generate_spec(graph, mode="sync", params=None):
return {
"version": "v2",
"parameters": params,
"parameters": params or {},
"graph": graph,
"load_mode": mode,
"verbose": True,
Expand Down

0 comments on commit cc385be

Please sign in to comment.