Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Apr 25, 2023

Copy link
Copy Markdown

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from JoshCrosby April 25, 2023 14:38

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread bin/six.py
@@ -20,6 +20,7 @@

"""Utilities for writing code that runs on Python 2 and 3"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 38-38 refactored with the following changes:

Comment thread bin/six.py
Comment on lines -148 to +149
if old_attr is None:
new_attr = name
else:
new_attr = old_attr
new_attr = name if old_attr is None else old_attr

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MovedAttribute.__init__ refactored with the following changes:

Comment thread bin/six.py
Comment on lines -179 to +177
self.known_modules[self.name + "." + fullname] = mod
self.known_modules[f"{self.name}.{fullname}"] = mod

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _SixMetaPathImporter._add_module refactored with the following changes:

Comment thread bin/six.py
Comment on lines -182 to +180
return self.known_modules[self.name + "." + fullname]
return self.known_modules[f"{self.name}.{fullname}"]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _SixMetaPathImporter._get_module refactored with the following changes:

Comment thread bin/six.py
Comment on lines -185 to +183
if fullname in self.known_modules:
return self
return None
return self if fullname in self.known_modules else None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _SixMetaPathImporter.find_module refactored with the following changes:

Comment thread bin/awscli/argprocess.py
"""
full_message = ("Error parsing parameter '%s': %s" %
(cli_name, message))
full_message = f"Error parsing parameter '{cli_name}': {message}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ParamError.__init__ refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -77 to +81
'load-cli-arg.%s.%s.%s' % (service_name,
operation_name,
param_name),
param=cli_argument, value=value, service_name=service_name,
operation_name=operation_name)
f'load-cli-arg.{service_name}.{operation_name}.{param_name}',
param=cli_argument,
value=value,
service_name=service_name,
operation_name=operation_name,
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unpack_argument refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -114 to +121
return 'structure(%s)' % ', '.join(sorted(set(sub_types)))
return f"structure({', '.join(sorted(set(sub_types)))})"
elif param.type_name == 'list':
return 'list-%s' % _detect_shape_structure(param.member, stack)
return f'list-{_detect_shape_structure(param.member, stack)}'
elif param.type_name == 'map':
if param.value.type_name in SCALAR_TYPES:
return 'map-scalar'
else:
return 'map-%s' % _detect_shape_structure(param.value, stack)
return f'map-{_detect_shape_structure(param.value, stack)}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _detect_shape_structure refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -148 to +152
if model.serialization.get('jsonvalue') and \
model.serialization.get('location') == 'header' and \
model.type_name == 'string':
return True
return False
return bool(
model.serialization.get('jsonvalue')
and model.serialization.get('location') == 'header'
and model.type_name == 'string'
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _special_type refactored with the following changes:

Comment thread bin/awscli/argprocess.py
def _unpack_complex_cli_arg(argument_model, value, cli_name):
type_name = argument_model.type_name
if type_name == 'structure' or type_name == 'map':
if type_name in ['structure', 'map']:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _unpack_complex_cli_arg refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -216 to +218
if argument_model.type_name == 'integer' or argument_model.type_name == 'long':
if argument_model.type_name in ['integer', 'long']:
return int(value)
elif argument_model.type_name == 'float' or argument_model.type_name == 'double':
elif argument_model.type_name in ['float', 'double']:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unpack_scalar_cli_arg refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

Comment thread bin/awscli/argprocess.py
Comment on lines -310 to +313
else:
service_id, operation_name = \
service_id, operation_name = \
find_service_and_method_in_event_name(event_name)
return self._parse_as_shorthand(
cli_argument, value, service_id, operation_name)
return self._parse_as_shorthand(
cli_argument, value, service_id, operation_name)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ParamShorthandParser.__call__ refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -332 to +334
self._visitor.visit(parsed, cli_argument.argument_model)
else:
# Otherwise value is just a string.
parsed = self._parser.parse(value)
self._visitor.visit(parsed, cli_argument.argument_model)
self._visitor.visit(parsed, cli_argument.argument_model)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ParamShorthandParser._parse_as_shorthand refactored with the following changes:

Comment thread bin/awscli/argprocess.py
self._uses_old_list_case(service_id, operation_name, cli_argument.name):
model.member.type_name == 'structure' and \
len(model.member.members) == 1 and \
self._uses_old_list_case(service_id, operation_name, cli_argument.name):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ParamShorthandParser._handle_special_cases refactored with the following changes:

Comment thread bin/awscli/argprocess.py
Comment on lines -386 to +383
if value and isinstance(value, list):
check_val = value[0]
else:
check_val = value
check_val = value[0] if value and isinstance(value, list) else value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ParamShorthandParser._should_parse_as_shorthand refactored with the following changes:

Comment thread bin/awscli/arguments.py
Comment on lines -286 to +280
if self._required is None:
return False
return self._required
return False if self._required is None else self._required

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CustomArgument.required refactored with the following changes:

Comment thread bin/awscli/arguments.py
Comment on lines -313 to +305
cli_type = str
if self._action in ['store_true', 'store_false']:
cli_type = bool
return cli_type
return bool if self._action in ['store_true', 'store_false'] else str

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CustomArgument.cli_type refactored with the following changes:

Comment thread bin/awscli/arguments.py
Comment on lines -441 to +444
else:
# This is a two step process. First is the process of converting
# the command line value into a python value. Normally this is
# handled by argparse directly, but there are cases where extra
# processing is needed. For example, "--foo name=value" the value
# can be converted from "name=value" to {"name": "value"}. This is
# referred to as the "unpacking" process. Once we've unpacked the
# argument value, we have to decide how this is converted into
# something that can be consumed by botocore. Many times this is
# just associating the key and value in the params dict as down
# below. Sometimes this can be more complicated, and subclasses
# can customize as they need.
unpacked = self._unpack_argument(value)
LOG.debug('Unpacked value of %r for parameter "%s": %r', value,
self.py_name, unpacked)
parameters[self._serialized_name] = unpacked
# This is a two step process. First is the process of converting
# the command line value into a python value. Normally this is
# handled by argparse directly, but there are cases where extra
# processing is needed. For example, "--foo name=value" the value
# can be converted from "name=value" to {"name": "value"}. This is
# referred to as the "unpacking" process. Once we've unpacked the
# argument value, we have to decide how this is converted into
# something that can be consumed by botocore. Many times this is
# just associating the key and value in the params dict as down
# below. Sometimes this can be more complicated, and subclasses
# can customize as they need.
unpacked = self._unpack_argument(value)
LOG.debug('Unpacked value of %r for parameter "%s": %r', value,
self.py_name, unpacked)
parameters[self._serialized_name] = unpacked

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIArgument.add_to_params refactored with the following changes:

Comment thread bin/awscli/arguments.py
Comment on lines -461 to +455
override = self._emit_first_response('process-cli-arg.%s.%s' % (
service_name, operation_name), param=self.argument_model,
cli_argument=self, value=value)
if override is not None:
# A plugin supplied an alternate conversion,
# use it instead.
return override
else:
# Fall back to the default arg processing.
return unpack_cli_arg(self, value)
override = self._emit_first_response(
f'process-cli-arg.{service_name}.{operation_name}',
param=self.argument_model,
cli_argument=self,
value=value,
)
return override if override is not None else unpack_cli_arg(self, value)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIArgument._unpack_argument refactored with the following changes:

This removes the following comments ( why? ):

# use it instead.
# A plugin supplied an alternate conversion,
# Fall back to the default arg processing.

Comment thread bin/awscli/arguments.py
Comment on lines -520 to +506
if dest is None:
self._destination = self.py_name
else:
self._destination = dest
if group_name is None:
self._group_name = self.name
else:
self._group_name = group_name
self._destination = self.py_name if dest is None else dest
self._group_name = self.name if group_name is None else group_name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BooleanArgument.__init__ refactored with the following changes:

Comment thread bin/awscli/arguments.py
Comment on lines -546 to +525
negative_name = 'no-%s' % self.name
negative_name = f'no-{self.name}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BooleanArgument.add_to_arg_table refactored with the following changes:

Comment thread bin/awscli/clidocs.py
if is_json_value_header(shape):
return 'JSON'
return default
return 'JSON' if is_json_value_header(shape) else default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIDocumentEventHandler._get_argument_type_name refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -95 to +93
doc.write(':ref:`%s <cli:%s>`' % (cmd, full_cmd_name))
doc.write(f':ref:`{cmd} <cli:{full_cmd_name}>`')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIDocumentEventHandler.doc_breadcrumbs refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -103 to +102
reference = 'aws ' + reference
doc.writeln('.. _cli:%s:' % reference)
reference = f'aws {reference}'
doc.writeln(f'.. _cli:{reference}:')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIDocumentEventHandler.doc_title refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -118 to +116
doc.writeln('%s' % help_command.name)
doc.writeln(f'{help_command.name}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CLIDocumentEventHandler.doc_synopsis_start refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -367 to +362
doc.write('%s, ...' % self._json_example_value_name(argument_model.member))
doc.write(f'{self._json_example_value_name(argument_model.member)}, ...')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OperationDocumentEventHandler._do_json_example refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -404 to +401
doc.write('"%s": %s' % (member_name,
self._json_example_value_name(member_model)))
elif member_type_name == 'structure':
doc.write('"%s": ' % member_name)
self._json_example(doc, member_model, stack)
elif member_type_name == 'map':
doc.write('"%s": ' % member_name)
self._json_example(doc, member_model, stack)
elif member_type_name == 'list':
doc.write('"%s": ' % member_name)
doc.write(f'"{member_name}": {self._json_example_value_name(member_model)}')
elif member_type_name in ['structure', 'map', 'list']:
doc.write(f'"{member_name}": ')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OperationDocumentEventHandler._doc_input_structure_members refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -424 to +421
find_service_and_method_in_event_name(event_name)
find_service_and_method_in_event_name(event_name)
doc = help_command.doc
cli_argument = help_command.arg_table[arg_name]
if cli_argument.group_name in self._arg_groups:
if cli_argument.group_name in self._documented_arg_groups:
# Args with group_names (boolean args) don't
# need to generate example syntax.
return
if (
cli_argument.group_name in self._arg_groups
and cli_argument.group_name in self._documented_arg_groups
):
# Args with group_names (boolean args) don't
# need to generate example syntax.
return

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OperationDocumentEventHandler.doc_option_example refactored with the following changes:

Comment thread bin/awscli/clidocs.py
Comment on lines -497 to +490
if member_shape.name in stack:
# Document the recursion once, otherwise just
# note the fact that it's recursive and return.
if stack.count(member_shape.name) > 1:
if member_shape.type_name == 'structure':
doc.write('( ... recursive ... )')
return
if member_shape.name in stack and stack.count(member_shape.name) > 1:
if member_shape.type_name == 'structure':
doc.write('( ... recursive ... )')
return

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OperationDocumentEventHandler._doc_member_for_output refactored with the following changes:

This removes the following comments ( why? ):

# Document the recursion once, otherwise just
# note the fact that it's recursive and return.

Comment thread bin/awscli/clidocs.py
Comment on lines -517 to +504
doc.write('(%s)' % member_shape.type_name)
doc.write(f'({member_shape.type_name})')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OperationDocumentEventHandler._do_doc_member_for_output refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants