Skip to content

Commit 3068c02

Browse files
committed
cc userver: reformat Python code according to Ruff rules
commit_hash:340c31c5395290be9ef8f4e438447f3b7dd1b80a
1 parent f8c46d8 commit 3068c02

File tree

102 files changed

+278
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+278
-300
lines changed

chaotic-openapi/chaotic_openapi/back/cpp_client/middleware.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,20 @@ def request_member_name(self) -> str:
3333
"""
3434
Generated `Request` member name for middleware data.
3535
"""
36-
pass # noqa: PIE790
3736

3837
@property
3938
@abc.abstractmethod
4039
def request_member_cpp_type(self) -> str:
4140
"""
4241
C++ type of `request_member_name`.
4342
"""
44-
pass # noqa: PIE790
4543

4644
@property
4745
@abc.abstractmethod
4846
def requests_hpp_includes(self) -> list[str]:
4947
"""
5048
C++ include path used to access `request_member_cpp_type`.
5149
"""
52-
pass # noqa: PIE790
5350

5451
@abc.abstractmethod
5552
def write_member_command(
@@ -65,7 +62,6 @@ def write_member_command(
6562
sink - variable name of `ParameterSinkHttpClient` type
6663
http_request - variable name of `clients::http::Request` type
6764
"""
68-
pass # noqa: PIE790
6965

7066

7167
class MiddlewarePlugin(abc.ABC):
@@ -84,7 +80,6 @@ def field(self) -> str:
8480
Returns `x-usrv-middleware` property name that is responsible for
8581
middleware activation and parameters storage.
8682
"""
87-
pass # noqa: PIE790
8883

8984
@abc.abstractmethod
9085
def create(self, args: dict) -> Middleware:
@@ -93,4 +88,3 @@ def create(self, args: dict) -> Middleware:
9388
"x-usrv-middleware." + field property is discovered.
9489
It creates a per-operation `Middleware` object.
9590
"""
96-
pass # noqa: PIE790

chaotic-openapi/chaotic_openapi/back/cpp_client/translator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def translate(
6363
namespaces={schema.source_location().filepath: '' for schema in service.schemas.values()},
6464
infile_to_name_func=self.map_infile_path_to_cpp_type,
6565
include_dirs=self._include_dirs,
66-
) # noqa: COM812
66+
),
6767
)
6868
self._spec.schemas = gen.generate_types(resolved_schemas)
6969
self._raw_schemas = {str(schema.source_location()): schema for schema in service.schemas.values()}
@@ -131,7 +131,7 @@ def map_infile_path_to_cpp_type(self, name: str, stem: str) -> str:
131131

132132
match = re.fullmatch(
133133
'/paths/\\[([^\\]]*)\\]/([a-zA-Z]*)/responses/([0-9]*)/headers/([-a-zA-Z0-9_]*)/schema',
134-
name, # noqa: COM812
134+
name,
135135
)
136136
if match:
137137
return '{}::{}::{}::Response{}Header{}'.format(
@@ -249,7 +249,7 @@ def _translate_single_schema(self, schema: chaotic_types.Schema) -> cpp_types.Cp
249249
namespaces={schema.source_location().filepath: ''},
250250
infile_to_name_func=self.map_infile_path_to_cpp_type,
251251
include_dirs=self._include_dirs,
252-
) # noqa: COM812
252+
),
253253
)
254254
gen_types = gen.generate_types(
255255
resolved_schemas,
@@ -272,7 +272,7 @@ def _translate_response(
272272
response = self._raw_responses[response.ref]
273273

274274
headers = []
275-
for name, header in response.headers.items(): # noqa: PERF102
275+
for header in response.headers.values():
276276
headers.append(self._translate_parameter(header))
277277

278278
body = {}

chaotic-openapi/chaotic_openapi/back/cpp_client/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def responses_declaration_includes(self) -> list[str]:
221221
continue
222222

223223
for response in op.responses:
224-
for _, body in response.body.items(): # noqa: PERF102
224+
for body in response.body.values():
225225
includes.update(body.declaration_includes())
226226
for header in response.headers:
227227
includes.update(header.declaration_includes())
@@ -234,7 +234,7 @@ def responses_definitions_includes(self) -> list[str]:
234234
continue
235235

236236
for response in op.responses:
237-
for _, body in response.body.items(): # noqa: PERF102
237+
for body in response.body.values():
238238
includes.update(body.definition_includes())
239239
return sorted(includes)
240240

chaotic-openapi/chaotic_openapi/back/linter/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import argparse # noqa: I001
1+
import argparse
22
import json
33
import pprint
44

chaotic-openapi/chaotic_openapi/back/linter/validators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys # noqa: I001
1+
import sys
22

33
from chaotic.front import types
44
from chaotic_openapi.front import model
@@ -17,15 +17,15 @@ def validate(service: model.Service) -> None:
1717

1818
def validate_nonobject_body(service: model.Service) -> None:
1919
for operation in service.operations:
20-
for content_type, body in operation.requestBody.items(): # noqa: PERF102
20+
for body in operation.requestBody.values():
2121
if isinstance(body, types.Ref):
2222
schema = service.schemas[body.ref]
2323
else:
2424
schema = body
2525

2626
if not isinstance(
2727
schema,
28-
(types.SchemaObject, types.OneOfWithDiscriminator, types.OneOfWithoutDiscriminator), # noqa: COM812
28+
(types.SchemaObject, types.OneOfWithDiscriminator, types.OneOfWithoutDiscriminator),
2929
):
3030
report_error('non-object-body', schema.source_location(), 'Non-object type in body root is forbidden')
3131

@@ -44,11 +44,11 @@ def visitor(child: types.Schema, _: types.Schema):
4444
report_error(
4545
'dash-in-field-name',
4646
child.source_location(),
47-
'Dash in field name is useless for JS/Typescript', # noqa: COM812
47+
'Dash in field name is useless for JS/Typescript',
4848
)
4949

5050
for operation in service.operations:
51-
for content_type, body in operation.requestBody.items(): # noqa: PERF102
51+
for body in operation.requestBody.values():
5252
if isinstance(body, types.Ref):
5353
schema = service.schemas[body.ref]
5454
else:

chaotic-openapi/chaotic_openapi/front/base_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def model_post_init(self, context: Any) -> None:
1717
continue
1818
if field.startswith('x-taxi-go-'):
1919
continue
20-
if field.startswith('x-taxi-') or field.startswith('x-usrv-'): # noqa: PIE810
20+
if field.startswith(('x-taxi-', 'x-usrv-')):
2121
assert field in self._model_userver_tags, f'Field {field} is not allowed in this context'
2222
continue
2323

chaotic-openapi/chaotic_openapi/front/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ def validate_security(self, security: Security | None) -> None:
339339
for name, values in security.items():
340340
if name not in self.components.securitySchemes:
341341
raise ValueError(
342-
f'Undefined security name="{name}". Expected on of: {self.components.securitySchemes.keys()}' # noqa: COM812
342+
f'Undefined security name="{name}". Expected on of: {self.components.securitySchemes.keys()}',
343343
)
344344
sec_scheme = self.components.securitySchemes[name]
345345

346346
if isinstance(sec_scheme, Ref):
347347
if sec_scheme not in self.components.securitySchemes:
348348
raise ValueError(
349-
f'Invalid reference "{sec_scheme}". Expected one of: "{self.components.securitySchemes.keys()}"' # noqa: COM812
349+
f'Invalid reference "{sec_scheme}". Expected one of: "{self.components.securitySchemes.keys()}"',
350350
)
351351
elif isinstance(sec_scheme, SecurityScheme):
352352
if sec_scheme.type not in [SecurityType.oauth2, SecurityType.openIdConnect]:

chaotic-openapi/chaotic_openapi/front/parser.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _convert_swagger_request_body(
196196
def _convert_swagger_parameter(
197197
self,
198198
parameter: swagger.Parameter | swagger.Ref,
199-
infile_path: str, # noqa: COM812
199+
infile_path: str,
200200
) -> model.Parameter:
201201
if isinstance(parameter, swagger.Ref):
202202
return self._state.service.parameters[self._locate_ref(parameter.ref)]
@@ -270,7 +270,7 @@ def _convert_swagger_response(
270270
self,
271271
response: swagger.Response | swagger.Ref,
272272
produces: list[str],
273-
infile_path: str, # noqa: COM812
273+
infile_path: str,
274274
) -> model.Response | model.Ref:
275275
assert infile_path.count('#') <= 1
276276

@@ -324,7 +324,7 @@ def _convert_openapi_request_body(
324324
content_type=content_type,
325325
schema=schema,
326326
required=request_body.required,
327-
) # noqa: COM812
327+
)
328328
)
329329
return requestBody
330330

@@ -346,15 +346,15 @@ def _convert_openapi_flows(self, flows: openapi.OAuthFlows) -> list[model.Flow]:
346346
authCode = flows.authorizationCode
347347
refreshUrl = authCode.refreshUrl or ''
348348
model_flows.append(
349-
model.AuthCodeFlow(refreshUrl, authCode.scopes, authCode.authorizationUrl, authCode.tokenUrl) # noqa: COM812
349+
model.AuthCodeFlow(refreshUrl, authCode.scopes, authCode.authorizationUrl, authCode.tokenUrl),
350350
)
351351

352352
return model_flows
353353

354354
def _convert_openapi_securuty(
355355
self,
356356
security_scheme: openapi.SecurityScheme | openapi.Ref,
357-
flows_scopes: list[str] | None = None, # noqa: COM812
357+
flows_scopes: list[str] | None = None,
358358
) -> model.Security:
359359
if isinstance(security_scheme, openapi.Ref):
360360
return self._state.service.security[self._locate_ref(security_scheme.ref)]
@@ -385,7 +385,7 @@ def _convert_openapi_securuty(
385385
def _convert_swagger_security(
386386
self,
387387
security_def: swagger.SecurityDef,
388-
flows_scopes: list[str] | None = None, # noqa: COM812
388+
flows_scopes: list[str] | None = None,
389389
) -> model.Security:
390390
description = security_def.description or ''
391391
match security_def.type:
@@ -564,7 +564,7 @@ def _convert_op_security(security: swagger.Security | None) -> list[model.Securi
564564
if self._is_swagger_request_body(sw_path_parameter, global_params):
565565
sw_path_body = self._convert_swagger_request_body(
566566
sw_path_parameter,
567-
infile_path + f'/requestBodies/{i}', # noqa: COM812
567+
infile_path + f'/requestBodies/{i}',
568568
)
569569
else:
570570
sw_param = self._convert_swagger_parameter(sw_path_parameter, infile_path + f'/parameters/{i}')
@@ -582,7 +582,7 @@ def _convert_op_params(
582582
body = self._convert_swagger_request_body(
583583
sw_parameter,
584584
infile_path + '/requestBody',
585-
consumes, # noqa: COM812
585+
consumes,
586586
)
587587
else:
588588
param = self._convert_swagger_parameter(sw_parameter, infile_path + f'/parameters/{i}')
@@ -595,49 +595,49 @@ def _convert_op_params(
595595
'get',
596596
sw_path_item.get,
597597
_convert_op_security,
598-
_convert_op_params, # noqa: COM812
598+
_convert_op_params,
599599
)
600600
self._append_swagger_operation(
601601
parsed.basePath + sw_path,
602602
'post',
603603
sw_path_item.post,
604604
_convert_op_security,
605-
_convert_op_params, # noqa: COM812
605+
_convert_op_params,
606606
)
607607
self._append_swagger_operation(
608608
parsed.basePath + sw_path,
609609
'put',
610610
sw_path_item.put,
611611
_convert_op_security,
612-
_convert_op_params, # noqa: COM812
612+
_convert_op_params,
613613
)
614614
self._append_swagger_operation(
615615
parsed.basePath + sw_path,
616616
'delete',
617617
sw_path_item.delete,
618618
_convert_op_security,
619-
_convert_op_params, # noqa: COM812
619+
_convert_op_params,
620620
)
621621
self._append_swagger_operation(
622622
parsed.basePath + sw_path,
623623
'options',
624624
sw_path_item.options,
625625
_convert_op_security,
626-
_convert_op_params, # noqa: COM812
626+
_convert_op_params,
627627
)
628628
self._append_swagger_operation(
629629
parsed.basePath + sw_path,
630630
'head',
631631
sw_path_item.head,
632632
_convert_op_security,
633-
_convert_op_params, # noqa: COM812
633+
_convert_op_params,
634634
)
635635
self._append_swagger_operation(
636636
parsed.basePath + sw_path,
637637
'patch',
638638
sw_path_item.patch,
639639
_convert_op_security,
640-
_convert_op_params, # noqa: COM812
640+
_convert_op_params,
641641
)
642642
self._make_sure_operations_are_unique()
643643
else:
@@ -730,7 +730,7 @@ def _append_openapi_operation(
730730
security=security_converter(operation.security),
731731
x_middlewares=operation.x_taxi_middlewares or base_model.XMiddlewares(tvm=True),
732732
x_client_codegen=operation.x_client_codegen,
733-
) # noqa: COM812
733+
),
734734
)
735735

736736
def _append_swagger_operation(
@@ -763,14 +763,14 @@ def _append_swagger_operation(
763763
int(status): self._convert_swagger_response(
764764
response,
765765
operation.produces,
766-
infile_path + f'/responses/{status}', # noqa: COM812
766+
infile_path + f'/responses/{status}',
767767
)
768768
for status, response in operation.responses.items()
769769
},
770770
security=security_converter(operation.security),
771771
x_middlewares=operation.x_taxi_middlewares or base_model.XMiddlewares(tvm=True),
772772
x_client_codegen=operation.x_client_codegen,
773-
) # noqa: COM812
773+
),
774774
)
775775

776776
def service(self) -> model.Service:

chaotic-openapi/chaotic_openapi/front/ref_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def normalize_ref(filepath: str, ref_: str) -> str:
1414
'{}/{}'.format(
1515
filepath.rsplit('/', 1)[0],
1616
ref_,
17-
) # noqa: COM812
17+
),
1818
)
1919

2020

chaotic-openapi/tests/back/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from chaotic_openapi.back.cpp_client import translator # noqa: I001
1+
from chaotic_openapi.back.cpp_client import translator
22
from chaotic_openapi.front import parser as front_parser
33
import pytest
44

0 commit comments

Comments
 (0)