Skip to content

Commit

Permalink
Update black (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Apr 20, 2024
1 parent 35aced7 commit c58781d
Show file tree
Hide file tree
Showing 433 changed files with 1,433 additions and 2,167 deletions.
2 changes: 1 addition & 1 deletion eng/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ debugpy==1.8.1
pytest==8.1.1
tox==4.14.2
coverage==7.4.4
black==22.12.0
black==24.4.0
8 changes: 5 additions & 3 deletions packages/autorest.python/autorest/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ def build_policies(
"self._config.user_agent_policy",
"self._config.proxy_policy",
"policies.ContentDecodePolicy(**kwargs)",
f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
if is_arm
else None,
(
f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
if is_arm
else None
),
"self._config.redirect_policy",
"self._config.retry_policy",
"self._config.authentication_policy",
Expand Down
8 changes: 5 additions & 3 deletions packages/autorest.python/autorest/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def company_name(self) -> str:
def license_header(self) -> str:
license_header = self.options.get(
"header-text",
DEFAULT_HEADER_TEXT.format(company_name=self.company_name)
if self.company_name
else "",
(
DEFAULT_HEADER_TEXT.format(company_name=self.company_name)
if self.company_name
else ""
),
)
if license_header:
license_header = license_header.replace("\n", "\n# ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,13 @@ def pylint_disable(self) -> str:
return ""

@abstractmethod
def response_type_annotation(self, **kwargs) -> str:
...
def response_type_annotation(self, **kwargs) -> str: ...

@abstractmethod
def response_docstring_text(self, **kwargs) -> str:
...
def response_docstring_text(self, **kwargs) -> str: ...

@abstractmethod
def response_docstring_type(self, **kwargs) -> str:
...
def response_docstring_type(self, **kwargs) -> str: ...

@property
def description(self) -> str:
Expand Down
8 changes: 5 additions & 3 deletions packages/autorest.python/autorest/codegen/models/enum_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ def imports(self, **kwargs: Any) -> FileImport:
"models",
ImportType.LOCAL,
alias="_models",
typing_section=TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR,
typing_section=(
TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR
),
)
return file_import
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=multiple-statements
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
Expand Down Expand Up @@ -151,5 +152,4 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
return file_import


class LROOperation(LROOperationBase[LROResponse]):
...
class LROOperation(LROOperationBase[LROResponse]): ...
22 changes: 13 additions & 9 deletions packages/autorest.python/autorest/codegen/models/model_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def get_json_template_representation(
]
}
if self.discriminator and self.discriminator_value:
representation[
f'"{self.discriminator.wire_name}"'
] = f'"{self.discriminator_value}"'
representation[f'"{self.discriminator.wire_name}"'] = (
f'"{self.discriminator_value}"'
)

# once we've finished, we want to reset created_json_template_representation to false
# so we can call it again
Expand Down Expand Up @@ -333,18 +333,22 @@ def imports(self, **kwargs: Any) -> FileImport:
"models",
ImportType.LOCAL,
alias="_models",
typing_section=TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR,
typing_section=(
TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR
),
)
if self.is_form_data:
file_import.add_submodule_import(
relative_path,
"_model_base",
ImportType.LOCAL,
typing_section=TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR,
typing_section=(
TypingSection.TYPING
if kwargs.get("model_typing")
else TypingSection.REGULAR
),
)
return file_import

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=multiple-statements
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
Expand Down Expand Up @@ -182,5 +183,4 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
return file_import


class PagingOperation(PagingOperationBase[PagingResponse]):
...
class PagingOperation(PagingOperationBase[PagingResponse]): ...
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ def docstring_type_keyword(self) -> str:

@property
@abc.abstractmethod
def in_method_signature(self) -> bool:
...
def in_method_signature(self) -> bool: ...

def method_signature(self, async_mode: bool) -> str:
type_annot = self.type_annotation(async_mode=async_mode)
Expand Down
32 changes: 20 additions & 12 deletions packages/autorest.python/autorest/codegen/models/primitive_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,26 @@ def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
@property
def serialization_constraints(self) -> List[str]:
validation_constraints = [
f"maximum_ex={self.maximum}"
if self.maximum is not None and self.exclusive_maximum
else None,
f"maximum={self.maximum}"
if self.maximum is not None and not self.exclusive_maximum
else None,
f"minimum_ex={self.minimum}"
if self.minimum is not None and self.exclusive_minimum
else None,
f"minimum={self.minimum}"
if self.minimum is not None and not self.exclusive_minimum
else None,
(
f"maximum_ex={self.maximum}"
if self.maximum is not None and self.exclusive_maximum
else None
),
(
f"maximum={self.maximum}"
if self.maximum is not None and not self.exclusive_maximum
else None
),
(
f"minimum_ex={self.minimum}"
if self.minimum is not None and self.exclusive_minimum
else None
),
(
f"minimum={self.minimum}"
if self.minimum is not None and not self.exclusive_minimum
else None
),
f"multiple={self.multiple}" if self.multiple else None,
]
return [x for x in validation_constraints if x is not None]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ def imports(self) -> FileImport:
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
)
file_import.add_msrest_import(
relative_path="..."
if (
not self.code_model.options["builders_visibility"] == "embedded"
and self.group_name
)
else "..",
relative_path=(
"..."
if (
not self.code_model.options["builders_visibility"] == "embedded"
and self.group_name
)
else ".."
),
msrest_import_type=MsrestImportType.Serializer,
typing_section=TypingSection.REGULAR,
)
Expand All @@ -137,8 +139,7 @@ def imports(self) -> FileImport:
@abstractmethod
def parameter_list_type() -> (
Callable[[Dict[str, Any], "CodeModel"], ParameterListType]
):
...
): ...

@classmethod
def get_name(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-lines,multiple-statements
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
Expand Down Expand Up @@ -262,8 +262,7 @@ def __init__(self, code_model: CodeModel, async_mode: bool) -> None:

@property
@abstractmethod
def _need_self_param(self) -> bool:
...
def _need_self_param(self) -> bool: ...

@property
@abstractmethod
Expand Down Expand Up @@ -378,8 +377,7 @@ def param_description_and_response_docstring(

@property
@abstractmethod
def _json_response_template_name(self) -> str:
...
def _json_response_template_name(self) -> str: ...

def _json_input_example_template(self, builder: BuilderType) -> List[str]:
template: List[str] = []
Expand Down Expand Up @@ -525,12 +523,16 @@ def pop_kwargs_from_signature(self, builder: RequestBuilderType) -> List[str]:
return self.parameter_serializer.pop_kwargs_from_signature(
builder.parameters.kwargs_to_pop,
check_kwarg_dict=True,
pop_headers_kwarg=PopKwargType.CASE_INSENSITIVE
if bool(builder.parameters.headers)
else PopKwargType.NO,
pop_params_kwarg=PopKwargType.CASE_INSENSITIVE
if bool(builder.parameters.query)
else PopKwargType.NO,
pop_headers_kwarg=(
PopKwargType.CASE_INSENSITIVE
if bool(builder.parameters.headers)
else PopKwargType.NO
),
pop_params_kwarg=(
PopKwargType.CASE_INSENSITIVE
if bool(builder.parameters.query)
else PopKwargType.NO
),
)

@staticmethod
Expand Down Expand Up @@ -711,16 +713,20 @@ def pop_kwargs_from_signature(self, builder: OperationType) -> List[str]:
kwargs = self.parameter_serializer.pop_kwargs_from_signature(
kwargs_to_pop,
check_kwarg_dict=True,
pop_headers_kwarg=PopKwargType.CASE_INSENSITIVE
if builder.has_kwargs_to_pop_with_default(
kwargs_to_pop, ParameterLocation.HEADER # type: ignore
)
else PopKwargType.SIMPLE,
pop_params_kwarg=PopKwargType.CASE_INSENSITIVE
if builder.has_kwargs_to_pop_with_default(
kwargs_to_pop, ParameterLocation.QUERY # type: ignore
)
else PopKwargType.SIMPLE,
pop_headers_kwarg=(
PopKwargType.CASE_INSENSITIVE
if builder.has_kwargs_to_pop_with_default(
kwargs_to_pop, ParameterLocation.HEADER # type: ignore
)
else PopKwargType.SIMPLE
),
pop_params_kwarg=(
PopKwargType.CASE_INSENSITIVE
if builder.has_kwargs_to_pop_with_default(
kwargs_to_pop, ParameterLocation.QUERY # type: ignore
)
else PopKwargType.SIMPLE
),
check_client_input=not self.code_model.options["multiapi"],
operation_name=f"('{builder.name}')" if builder.group_name == "" else "",
)
Expand Down Expand Up @@ -1217,9 +1223,11 @@ def handle_error_response(self, builder: OperationType) -> List[str]:
retval.append(
" raise HttpResponseError(response=response{}{})".format(
error_model,
", error_format=ARMErrorFormat"
if self.code_model.options["azure_arm"]
else "",
(
", error_format=ARMErrorFormat"
if self.code_model.options["azure_arm"]
else ""
),
)
)
return retval
Expand Down Expand Up @@ -1364,8 +1372,7 @@ def _call_method(self) -> str:
return "await " if self.async_mode else ""


class OperationSerializer(_OperationSerializer[Operation]):
...
class OperationSerializer(_OperationSerializer[Operation]): ...


############################## PAGING OPERATIONS ##############################
Expand Down Expand Up @@ -1552,8 +1559,7 @@ def set_up_params_for_pager(self, builder: PagingOperationType) -> List[str]:
return retval


class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]):
...
class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]): ...


############################## LRO OPERATIONS ##############################
Expand Down Expand Up @@ -1682,12 +1688,16 @@ def get_long_running_output(self, builder: LROOperationType) -> List[str]:
retval.append(" if cls:")
retval.append(
" return cls(pipeline_response, {}, {}){}".format(
"deserialized"
if builder.lro_response and builder.lro_response.type
else "None",
"response_headers"
if builder.lro_response and builder.lro_response.headers
else "{}",
(
"deserialized"
if builder.lro_response and builder.lro_response.type
else "None"
),
(
"response_headers"
if builder.lro_response and builder.lro_response.headers
else "{}"
),
" # type: ignore",
)
)
Expand All @@ -1696,8 +1706,7 @@ def get_long_running_output(self, builder: LROOperationType) -> List[str]:
return retval


class LROOperationSerializer(_LROOperationSerializer[LROOperation]):
...
class LROOperationSerializer(_LROOperationSerializer[LROOperation]): ...


############################## LRO PAGING OPERATIONS ##############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def send_request_signature_and_response_type_annotation(
send_request_signature = self._send_request_signature()
return utils.method_signature_and_response_type_annotation_template(
method_signature=send_request_signature,
response_type_annotation="Awaitable[AsyncHttpResponse]"
if async_mode
else "HttpResponse",
response_type_annotation=(
"Awaitable[AsyncHttpResponse]" if async_mode else "HttpResponse"
),
)

def _example_make_call(self, async_mode: bool) -> List[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def _json_serialize_imports(
if name_imports:
name_import_ordered_list = list(name_imports)
name_import_ordered_list.sort(
key=lambda e: _to_string(e) # type: ignore
if isinstance(e, (list, tuple))
else e
if isinstance(e, str)
else ""
key=lambda e: (
_to_string(e) # type: ignore
if isinstance(e, (list, tuple))
else e if isinstance(e, str) else ""
)
)
json_package_name_dictionary[package_name] = name_import_ordered_list
json_import_type_dictionary[import_type_key] = json_package_name_dictionary
Expand Down
Loading

0 comments on commit c58781d

Please sign in to comment.