From 482c4323ffa8a6cc1ffe76c855bccb3cb639ccdf Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 May 2022 09:35:06 +0800 Subject: [PATCH] code (#24253) --- .../packaging_tools/change_log.py | 18 ++++++++++++------ .../packaging_tools/code_report.py | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/azure-sdk-tools/packaging_tools/change_log.py b/tools/azure-sdk-tools/packaging_tools/change_log.py index ea1e6922725d..66455780b507 100644 --- a/tools/azure-sdk-tools/packaging_tools/change_log.py +++ b/tools/azure-sdk-tools/packaging_tools/change_log.py @@ -82,13 +82,18 @@ def operation(self, diff_entry): if remaining_path[0] == "parameters": old_parameters_list = self._old_report["operations"][operation_name]["functions"][function_name]['parameters'] new_parameters_list = self._new_report["operations"][operation_name]["functions"][function_name]['parameters'] - old_parameters = {param_name['name'] for param_name in old_parameters_list} - new_parameters = {param_name['name'] for param_name in new_parameters_list} + old_parameters = {param_name['name']: param_name for param_name in old_parameters_list} + new_parameters = {param_name['name']: param_name for param_name in new_parameters_list} + old_parameters_set = set(old_parameters.keys()) + new_parameters_set = set(new_parameters.keys()) # The new parameter is optional or not. Be breaking change for now. - for removed_parameter in old_parameters - new_parameters: + for removed_parameter in (old_parameters_set - new_parameters_set): self.breaking_changes.append(_REMOVE_OPERATION_PARAM.format(operation_name, function_name, removed_parameter)) - for added_parameter in new_parameters - old_parameters: - self.breaking_changes.append(_ADD_OPERATION_PARAM.format(operation_name, function_name,added_parameter)) + for added_parameter in (new_parameters_set - old_parameters_set): + if new_parameters[added_parameter]['type'] == 'KEYWORD_ONLY' and new_parameters[added_parameter]['has_default_value']: + self.features.append(_ADD_OPERATION_PARAM_FEATURE.format(operation_name, function_name, added_parameter)) + else: + self.breaking_changes.append(_ADD_OPERATION_PARAM.format(operation_name, function_name, added_parameter)) return raise NotImplementedError(f"Other situations. Be err for now: {str(remaining_path)}") @@ -151,7 +156,7 @@ def client(self): ## Features _ADD_OPERATION_GROUP = "Added operation group {}" _ADD_OPERATION = "Added operation {}.{}" -_ADD_OPERATION_PARAM = "Operation {}.{} has a new parameter {}" +_ADD_OPERATION_PARAM_FEATURE = "Operation {}.{} has a new optional and keyword-only parameter {}" _MODEL_PARAM_ADD = "Model {} has a new parameter {}" _MODEL_ADD = "Added model {}" @@ -164,6 +169,7 @@ def client(self): _MODEL_PARAM_DELETE = "Model {} no longer has parameter {}" _MODEL_PARAM_ADD_REQUIRED = "Model {} has a new required parameter {}" _MODEL_PARAM_CHANGE_REQUIRED = "Parameter {} of model {} is now required" +_ADD_OPERATION_PARAM = "Operation {}.{} has a new parameter {}" def build_change_log(old_report, new_report): diff --git a/tools/azure-sdk-tools/packaging_tools/code_report.py b/tools/azure-sdk-tools/packaging_tools/code_report.py index 60f45fbbbc10..5b77bbbc7936 100644 --- a/tools/azure-sdk-tools/packaging_tools/code_report.py +++ b/tools/azure-sdk-tools/packaging_tools/code_report.py @@ -125,6 +125,8 @@ def create_report_from_func(function_attr): func_content["parameters"].append( { "name": parameter.name, + "type": str(parameter.kind), + "has_default_value": not (parameter.default is parameter.empty) } ) return func_content