Skip to content

Commit

Permalink
Run ruff check --fix --unsafe-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Dec 20, 2024
1 parent 93d3896 commit 4466771
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 61 deletions.
12 changes: 5 additions & 7 deletions awscli/customizations/datapipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class DocSectionNotFoundError(Exception):

class ParameterDefinitionError(ParamValidationError):
def __init__(self, msg):
full_msg = ("Error in parameter: %s\n" % msg)
super(ParameterDefinitionError, self).__init__(full_msg)
full_msg = (f"Error in parameter: {msg}\n")
super().__init__(full_msg)
self.msg = msg


Expand Down Expand Up @@ -102,8 +102,7 @@ def document_translation(help_command, **kwargs):
# This should never happen, but in the rare case that it does
# we should be raising something with a helpful error message.
raise DocSectionNotFoundError(
'Could not find the "output" section for the command: %s'
% help_command)
f'Could not find the "output" section for the command: {help_command}')
doc.write('======\nOutput\n======')
doc.write(
'\nThe output of this command is the pipeline definition, which'
Expand Down Expand Up @@ -316,7 +315,7 @@ def add_to_params(self, parameters, value):
parameter_object[key] = value
except IndexError:
raise ParameterDefinitionError(
"Invalid inline parameter format: %s" % argument
f"Invalid inline parameter format: {argument}"
)
parsed = {'values': parameter_object}
parameter_values = translator.definition_to_parameter_values(parsed)
Expand Down Expand Up @@ -392,8 +391,7 @@ def _validate_status_choices(self, statuses):
for status in statuses:
if status not in self.VALID_STATUS:
raise ParamValidationError(
"Invalid status: %s, must be one of: %s" %
(status, ', '.join(self.VALID_STATUS))
"Invalid status: {}, must be one of: {}".format(status, ', '.join(self.VALID_STATUS))
)

def _list_runs(self, parsed_args, parsed_globals):
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/datapipeline/createdefaultroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CreateDefaultRoles(BasicCommand):
)

def __init__(self, session, formatter=None):
super(CreateDefaultRoles, self).__init__(session)
super().__init__(session)

def _run_main(self, parsed_args, parsed_globals, **kwargs):
"""Call to run the commands"""
Expand Down
10 changes: 4 additions & 6 deletions awscli/customizations/datapipeline/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class PipelineDefinitionError(ParamValidationError):
def __init__(self, msg, definition):
full_msg = (
"Error in pipeline definition: %s\n" % msg)
super(PipelineDefinitionError, self).__init__(full_msg)
f"Error in pipeline definition: {msg}\n")
super().__init__(full_msg)
self.msg = msg
self.definition = definition

Expand Down Expand Up @@ -75,8 +75,7 @@ def definition_to_api_objects(definition):
try:
element_id = element.pop('id')
except KeyError:
raise PipelineDefinitionError('Missing "id" key of element: %s' %
json.dumps(element), definition)
raise PipelineDefinitionError(f'Missing "id" key of element: {json.dumps(element)}', definition)
api_object = {'id': element_id}
# If a name is provided, then we use that for the name,
# otherwise the id is used for the name.
Expand All @@ -100,8 +99,7 @@ def definition_to_api_parameters(definition):
try:
parameter_id = element.pop('id')
except KeyError:
raise PipelineDefinitionError('Missing "id" key of parameter: %s' %
json.dumps(element), definition)
raise PipelineDefinitionError(f'Missing "id" key of parameter: {json.dumps(element)}', definition)
parameter_object = {'id': parameter_id}
# Now we need the attribute list. Each element in the attribute list
# is a dict with a 'key', 'stringValue'
Expand Down
8 changes: 3 additions & 5 deletions awscli/customizations/dlm/createdefaultrole.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ class CreateDefaultRole(BasicCommand):
'choices': [RESOURCE_TYPE_SNAPSHOT, RESOURCE_TYPE_IMAGE],
'help_text': (
"<p>The resource type for which the role needs to be created."
" The available options are '%s' and '%s'."
" This parameter defaults to '%s'.</p>"
% (RESOURCE_TYPE_SNAPSHOT, RESOURCE_TYPE_IMAGE,
RESOURCE_TYPE_SNAPSHOT))}
f" The available options are '{RESOURCE_TYPE_SNAPSHOT}' and '{RESOURCE_TYPE_IMAGE}'."
f" This parameter defaults to '{RESOURCE_TYPE_SNAPSHOT}'.</p>")}

]

def __init__(self, session):
super(CreateDefaultRole, self).__init__(session)
super().__init__(session)

def _run_main(self, parsed_args, parsed_globals):
"""Call to run the commands"""
Expand Down
12 changes: 6 additions & 6 deletions awscli/customizations/dynamodb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class DDBError(Exception):

class EmptyExpressionError(DDBError, ParamValidationError):
def __init__(self):
super(EmptyExpressionError, self).__init__(
super().__init__(
"Expressions must not be empty"
)


class LexerError(DDBError, ParamValidationError):
def __init__(self, expression, position, message):
underline = ' ' * position + '^'
error_message = '%s\n%s\n%s' % (message, expression, underline)
super(LexerError, self).__init__(error_message)
error_message = f'{message}\n{expression}\n{underline}'
super().__init__(error_message)


class ParserError(DDBError, ParamValidationError):
Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, token, expected_type, expression):
self.token = token
self.expression = expression
self.expected_type = expected_type
super(UnexpectedTokenError, self).__init__(message)
super().__init__(message)


class InvalidLiteralValueError(ParserError):
Expand All @@ -76,7 +76,7 @@ def __init__(self, token, message, expression):
)
self.token = token
self.expression = expression
super(InvalidLiteralValueError, self).__init__(error_message)
super().__init__(error_message)


class UnknownExpressionError(ParserError):
Expand All @@ -94,4 +94,4 @@ def __init__(self, start_token, expression):
)
self.start_token = start_token
self.expression = expression
super(UnknownExpressionError, self).__init__(message)
super().__init__(message)
32 changes: 16 additions & 16 deletions awscli/customizations/dynamodb/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,69 +49,69 @@ def _substitution_index(self):
return num_substituted + self._index_offset

def _visit(self, node):
method = getattr(self, '_visit_%s' % node['type'])
method = getattr(self, '_visit_{}'.format(node['type']))
return method(node)

def _visit_comparator(self, node):
left = self._visit(node['children'][0])
right = self._visit(node['children'][1])
expression = '%s%s %s' % (
expression = '{}{} {}'.format(
left, self.COMPARATORS[node['value']], right
)
return expression

def _visit_identifier(self, node):
identifier_replacement = '#n%s' % self._substitution_index()
identifier_replacement = f'#n{self._substitution_index()}'
self._identifiers[identifier_replacement] = node['value']
return '%s ' % identifier_replacement
return f'{identifier_replacement} '

def _visit_path_identifier(self, node):
left = self._visit(node['children'][0]).strip()
right = self._visit(node['children'][1])
return '%s.%s' % (left, right)
return f'{left}.{right}'

def _visit_index_identifier(self, node):
left = self._visit(node['children'][0]).strip()
return '%s[%s] ' % (left, node['value'])
return '{}[{}] '.format(left, node['value'])

def _visit_literal(self, node):
literal_replacement = ':n%s' % self._substitution_index()
literal_replacement = f':n{self._substitution_index()}'
self._literals[literal_replacement] = node['value']
return '%s ' % literal_replacement
return f'{literal_replacement} '

def _visit_sequence(self, node):
visited_children = []
for child in node['children']:
visited_children.append(self._visit(child).strip())
return '%s' % ', '.join(visited_children)
return '{}'.format(', '.join(visited_children))

def _visit_or_expression(self, node):
left = self._visit(node['children'][0])
right = self._visit(node['children'][1])
return '%sOR %s' % (left, right)
return f'{left}OR {right}'

def _visit_and_expression(self, node):
left = self._visit(node['children'][0])
right = self._visit(node['children'][1])
return '%sAND %s' % (left, right)
return f'{left}AND {right}'

def _visit_not_expression(self, node):
return 'NOT %s' % self._visit(node['children'][0])
return 'NOT {}'.format(self._visit(node['children'][0]))

def _visit_subexpression(self, node):
return '( %s) ' % self._visit(node['children'][0])
return '( {}) '.format(self._visit(node['children'][0]))

def _visit_function(self, node):
return '%s(%s) ' % (node['value'], self._visit_sequence(node).strip())
return '{}({}) '.format(node['value'], self._visit_sequence(node).strip())

def _visit_in_expression(self, node):
return '%sIN (%s) ' % (
return '{}IN ({}) '.format(
self._visit(node['children'][0]),
self._visit(node['children'][1]).strip(),
)

def _visit_between_expression(self, node):
return '%sBETWEEN %sAND %s' % (
return '{}BETWEEN {}AND {}'.format(
self._visit(node['children'][0]),
self._visit(node['children'][1]),
self._visit(node['children'][2]),
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/dynamodb/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class DynamoYAMLDumper(YAMLDumper):
def __init__(self):
super(DynamoYAMLDumper, self).__init__()
super().__init__()
self._yaml.representer.add_representer(
decimal.Decimal, self._represent_decimal
)
Expand All @@ -46,4 +46,4 @@ def dump(self, response, stream):
stream.write(str(response))
stream.write('\n')
return
super(DynamoYAMLDumper, self).dump(response, stream)
super().dump(response, stream)
10 changes: 5 additions & 5 deletions awscli/customizations/dynamodb/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def tokenize(self, expression):
yield self._consume_comparator()
else:
raise LexerError(
message='Unrecognized character %s' % self._current,
message=f'Unrecognized character {self._current}',
expression=self._expression,
position=self._position,
)
Expand Down Expand Up @@ -182,7 +182,7 @@ def _consume_number(self):
buff += self._current
if self._next() not in self.DIGITS:
raise LexerError(
message='Invalid fractional character %s' % self._current,
message=f'Invalid fractional character {self._current}',
position=self._position,
expression=self._expression,
)
Expand All @@ -192,7 +192,7 @@ def _consume_number(self):
buff += self._current
if self._next() not in self.INT_CHARS and self._current != '+':
raise LexerError(
message='Invalid exponential character %s' % self._current,
message=f'Invalid exponential character {self._current}',
position=self._position,
expression=self._expression,
)
Expand All @@ -210,7 +210,7 @@ def _consume_int(self):
buff += self._current
if not is_positive and len(buff) < 2:
raise LexerError(
message='Unknown token %s' % buff,
message=f'Unknown token {buff}',
position=self._position,
expression=self._expression,
)
Expand Down Expand Up @@ -278,7 +278,7 @@ def _consume_until(self, delimiter):
if self._current is None:
# We're at the EOF.
raise LexerError(
message="Unclosed %s delimiter" % delimiter,
message=f"Unclosed {delimiter} delimiter",
position=start,
expression=self._expression,
)
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/dynamodb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _parse_literal_map(self):
token=self._current,
expression=self._expression,
message=(
'Keys must be of type `str`, found `%s`' % type(key)
f'Keys must be of type `str`, found `{type(key)}`'
)
)
self._advance_if_match('literal')
Expand Down
8 changes: 4 additions & 4 deletions awscli/customizations/dynamodb/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PaginatedDDBCommand(DDBCommand):
]

def _build_arg_table(self):
arg_table = super(PaginatedDDBCommand, self)._build_arg_table()
arg_table = super()._build_arg_table()
for arg_data in self.PAGING_ARGS:
paging_arg = CustomArgument(**arg_data)
arg_table[arg_data['name']] = paging_arg
Expand Down Expand Up @@ -169,7 +169,7 @@ class SelectCommand(PaginatedDDBCommand):
_SUPPORTED_OUTPUT_TYPES = ('yaml',)

def _run_main(self, parsed_args, parsed_globals):
super(SelectCommand, self)._run_main(parsed_args, parsed_globals)
super()._run_main(parsed_args, parsed_globals)
self._select(parsed_args, parsed_globals)
return 0

Expand Down Expand Up @@ -200,7 +200,7 @@ def _select(self, parsed_args, parsed_globals):
self._dump_yaml(operation, response, parsed_globals)

def _get_client_args(self, parsed_args):
client_args = super(SelectCommand, self)._get_client_args(parsed_args)
client_args = super()._get_client_args(parsed_args)
client_args.update({
'TableName': parsed_args.table_name,
'ConsistentRead': parsed_args.consistent_read,
Expand Down Expand Up @@ -255,7 +255,7 @@ class PutCommand(DDBCommand):
]

def _run_main(self, parsed_args, parsed_globals):
super(PutCommand, self)._run_main(parsed_args, parsed_globals)
super()._run_main(parsed_args, parsed_globals)
self._yaml = YAML(typ='safe')
self._yaml.constructor.add_constructor(
'tag:yaml.org,2002:binary', self._load_binary
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/dynamodb/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _transform_parameters(self, model, params, transformation,
target_shape):
type_name = model.type_name
if type_name in ['structure', 'map', 'list']:
getattr(self, '_transform_%s' % type_name)(
getattr(self, f'_transform_{type_name}')(
model, params, transformation, target_shape)

def _transform_structure(self, model, params, transformation,
Expand Down
13 changes: 6 additions & 7 deletions awscli/customizations/dynamodb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class Binary:
"""
def __init__(self, value):
if not isinstance(value, BINARY_TYPES):
raise TypeError('Value must be of the following types: %s.' %
', '.join([str(t) for t in BINARY_TYPES]))
raise TypeError('Value must be of the following types: {}.'.format(', '.join([str(t) for t in BINARY_TYPES])))
self.value = value

def __eq__(self, other):
Expand All @@ -57,7 +56,7 @@ def __ne__(self, other):
return not self.__eq__(other)

def __repr__(self):
return 'Binary(%r)' % self.value
return f'Binary({self.value!r})'

def __str__(self):
return self.value
Expand Down Expand Up @@ -93,7 +92,7 @@ def serialize(self, value):
dictionaries can be directly passed to botocore methods.
"""
dynamodb_type = self._get_dynamodb_type(value)
serializer = getattr(self, '_serialize_%s' % dynamodb_type.lower())
serializer = getattr(self, f'_serialize_{dynamodb_type.lower()}')
return {dynamodb_type: serializer(value)}

def _get_dynamodb_type(self, value):
Expand Down Expand Up @@ -130,7 +129,7 @@ def _get_dynamodb_type(self, value):
dynamodb_type = LIST

else:
msg = 'Unsupported type "%s" for value "%s"' % (type(value), value)
msg = f'Unsupported type "{type(value)}" for value "{value}"'
raise TypeError(msg)

return dynamodb_type
Expand Down Expand Up @@ -251,10 +250,10 @@ def deserialize(self, value):
dynamodb_type = list(value.keys())[0]
try:
deserializer = getattr(
self, '_deserialize_%s' % dynamodb_type.lower())
self, f'_deserialize_{dynamodb_type.lower()}')
except AttributeError:
raise TypeError(
'Dynamodb type %s is not supported' % dynamodb_type)
f'Dynamodb type {dynamodb_type} is not supported')
return deserializer(value[dynamodb_type])

def _deserialize_null(self, value):
Expand Down

0 comments on commit 4466771

Please sign in to comment.