Skip to content

Commit

Permalink
Run ruff over codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Jun 10, 2024
1 parent f558bbb commit 50d25e9
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 127 deletions.
15 changes: 6 additions & 9 deletions boto3/docs/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def document_action(
example_resource_name = xform_name(resource_name)
if service_model.service_name == resource_name:
example_resource_name = resource_name
example_prefix = '{} = {}.{}'.format(
example_return_value, example_resource_name, action_model.name
example_prefix = (
f'{example_return_value} = {example_resource_name}.{action_model.name}'
)
full_action_name = (
f"{section.context.get('qualifier', '')}{action_model.name}"
Expand Down Expand Up @@ -193,13 +193,10 @@ def document_load_reload_action(
It is useful for generating docstrings.
"""
description = (
'Calls :py:meth:`{}.Client.{}` to update the attributes of the '
'{} resource. Note that the load and reload methods are '
'the same method and can be used interchangeably.'.format(
get_service_module_name(service_model),
xform_name(load_model.request.operation),
resource_name,
)
f'Calls :py:meth:`{get_service_module_name(service_model)}.Client.'
f'{xform_name(load_model.request.operation)}` to update the attributes of the '
f'{resource_name} resource. Note that the load and reload methods are '
'the same method and can be used interchangeably.'
)
example_resource_name = xform_name(resource_name)
if service_model.service_name == resource_name:
Expand Down
6 changes: 1 addition & 5 deletions boto3/docs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@ def _add_client_creation_example(self, section):
section.write('import boto3')
section.style.new_line()
section.style.new_line()
section.write(
'client = boto3.client(\'{service}\')'.format(
service=self._service_name
)
)
section.write(f'client = boto3.client(\'{self._service_name}\')')
section.style.end_codeblock()
31 changes: 5 additions & 26 deletions boto3/docs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@ def document_batch_action(
example_resource_name = xform_name(resource_name)
if service_model.service_name == resource_name:
example_resource_name = resource_name
example_prefix = '{} = {}.{}.{}'.format(
example_return_value,
example_resource_name,
collection_model.name,
batch_action_model.name,
)
example_prefix = f'{example_return_value} = {example_resource_name}.{collection_model.name}.{batch_action_model.name}'
document_model_driven_resource_method(
section=section,
method_name=batch_action_model.name,
Expand Down Expand Up @@ -229,11 +224,7 @@ def document_collection_method(
f'Creates an iterable of all {collection_model.resource.type} '
f'resources in the collection.'
),
'example_prefix': '{}_iterator = {}.{}.all'.format(
xform_name(collection_model.resource.type),
example_resource_name,
collection_model.name,
),
'example_prefix': f'{xform_name(collection_model.resource.type)}_iterator = {example_resource_name}.{collection_model.name}.all',
'exclude_input': underlying_operation_members,
},
'filter': {
Expand All @@ -245,11 +236,7 @@ def document_collection_method(
f'and extreme caution should be taken when performing actions '
f'on all resources.'
),
'example_prefix': '{}_iterator = {}.{}.filter'.format(
xform_name(collection_model.resource.type),
example_resource_name,
collection_model.name,
),
'example_prefix': f'{xform_name(collection_model.resource.type)}_iterator = {example_resource_name}.{collection_model.name}.filter',
'exclude_input': get_resource_ignore_params(
collection_model.request.params
),
Expand All @@ -259,11 +246,7 @@ def document_collection_method(
f'Creates an iterable up to a specified amount of '
f'{collection_model.resource.type} resources in the collection.'
),
'example_prefix': '{}_iterator = {}.{}.limit'.format(
xform_name(collection_model.resource.type),
example_resource_name,
collection_model.name,
),
'example_prefix': f'{xform_name(collection_model.resource.type)}_iterator = {example_resource_name}.{collection_model.name}.limit',
'include_input': [
DocumentedShape(
name='count',
Expand All @@ -282,11 +265,7 @@ def document_collection_method(
f'resources in the collection, but limits the number of '
f'items returned by each service call by the specified amount.'
),
'example_prefix': '{}_iterator = {}.{}.page_size'.format(
xform_name(collection_model.resource.type),
example_resource_name,
collection_model.name,
),
'example_prefix': f'{xform_name(collection_model.resource.type)}_iterator = {example_resource_name}.{collection_model.name}.page_size',
'include_input': [
DocumentedShape(
name='count',
Expand Down
4 changes: 2 additions & 2 deletions boto3/docs/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def document_model_driven_resource_method(
resource_type = resource_action_model.resource.type

new_return_section = section.add_new_section('return')
return_resource_type = '{}.{}'.format(
operation_model.service_model.service_name, resource_type
return_resource_type = (
f'{operation_model.service_model.service_name}.{resource_type}'
)

return_type = f':py:class:`{return_resource_type}`'
Expand Down
15 changes: 3 additions & 12 deletions boto3/docs/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def _add_intro(self, section):
def _add_description(self, section):
official_service_name = get_official_service_name(self._service_model)
section.write(
'A resource representing an {} {}'.format(
official_service_name, self._resource_name
)
f'A resource representing an {official_service_name} {self._resource_name}'
)

def _add_example(self, section, identifier_names):
Expand All @@ -103,19 +101,12 @@ def _add_example(self, section, identifier_names):
section.style.new_line()
section.style.new_line()
section.write(
'{} = boto3.resource(\'{}\')'.format(
self._service_name, self._service_name
)
f'{self._service_name} = boto3.resource(\'{self._service_name}\')'
)
section.style.new_line()
example_values = get_identifier_values_for_example(identifier_names)
section.write(
'{} = {}.{}({})'.format(
xform_name(self._resource_name),
self._service_name,
self._resource_name,
example_values,
)
f'{xform_name(self._resource_name)} = {self._service_name}.{self._resource_name}({example_values})'
)
section.style.end_codeblock()

Expand Down
12 changes: 2 additions & 10 deletions boto3/docs/subresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ def document_sub_resource(
example_resource_name = xform_name(resource_name)
if service_model.service_name == resource_name:
example_resource_name = resource_name
example = '{} = {}.{}({})'.format(
xform_name(sub_resource_model.resource.type),
example_resource_name,
sub_resource_model.name,
example_values,
)
example = f'{xform_name(sub_resource_model.resource.type)} = {example_resource_name}.{sub_resource_model.name}({example_values})'
example_section.style.start_codeblock()
example_section.write(example)
example_section.style.end_codeblock()
Expand All @@ -141,10 +136,7 @@ def document_sub_resource(
return_section = section.add_new_section('return')
return_section.style.new_line()
return_section.write(
':rtype: :py:class:`{}.{}`'.format(
get_service_module_name(service_model),
sub_resource_model.resource.type,
)
f':rtype: :py:class:`{get_service_module_name(service_model)}.{sub_resource_model.resource.type}`'
)
return_section.style.new_line()
return_section.write(
Expand Down
4 changes: 2 additions & 2 deletions boto3/docs/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def document_resource_waiter(
waiter_model.max_attempts,
)
)
example_prefix = '{}.{}'.format(
xform_name(resource_name), resource_waiter_model.name
example_prefix = (
f'{xform_name(resource_name)}.{resource_waiter_model.name}'
)
full_waiter_name = (
f"{section.context.get('qualifier', '')}{resource_waiter_model.name}"
Expand Down
4 changes: 1 addition & 3 deletions boto3/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def __init__(
self.resource_model = resource_model

def __repr__(self):
return 'ResourceMeta(\'{}\', identifiers={})'.format(
self.service_name, self.identifiers
)
return f'ResourceMeta(\'{self.service_name}\', identifiers={self.identifiers})'

def __eq__(self, other):
# Two metas are equal if their components are all equal
Expand Down
18 changes: 6 additions & 12 deletions boto3/resources/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def __repr__(self):
return '{}({}, {})'.format(
self.__class__.__name__,
self._parent,
'{}.{}'.format(
self._parent.meta.service_name, self._model.resource.type
),
f'{self._parent.meta.service_name}.{self._model.resource.type}',
)

def __iter__(self):
Expand Down Expand Up @@ -154,7 +152,7 @@ def pages(self):
paginator = client.get_paginator(self._py_operation_name)
pages = paginator.paginate(
PaginationConfig={'MaxItems': limit, 'PageSize': page_size},
**params
**params,
)
else:
logger.debug(
Expand Down Expand Up @@ -327,9 +325,7 @@ def __repr__(self):
return '{}({}, {})'.format(
self.__class__.__name__,
self._parent,
'{}.{}'.format(
self._parent.meta.service_name, self._model.resource.type
),
f'{self._parent.meta.service_name}.{self._model.resource.type}',
)

def iterator(self, **kwargs):
Expand Down Expand Up @@ -424,13 +420,11 @@ def load_from_definition(
)

if service_context.service_name == resource_name:
cls_name = '{}.{}Collection'.format(
service_context.service_name, collection_name
cls_name = (
f'{service_context.service_name}.{collection_name}Collection'
)
else:
cls_name = '{}.{}.{}Collection'.format(
service_context.service_name, resource_name, collection_name
)
cls_name = f'{service_context.service_name}.{resource_name}.{collection_name}Collection'

collection_cls = type(str(cls_name), (ResourceCollection,), attrs)

Expand Down
4 changes: 1 addition & 3 deletions boto3/resources/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@ def _load_name_with_category(self, names, name, category, snake_case=True):
# This isn't good, let's raise instead of trying to keep
# renaming this value.
raise ValueError(
'Problem renaming {} {} to {}!'.format(
self.name, category, name
)
f'Problem renaming {self.name} {category} to {name}!'
)

names.add(name)
Expand Down
4 changes: 1 addition & 3 deletions boto3/resources/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def build_empty_response(search_path, operation_name, service_model):
shape = shape.member
else:
raise NotImplementedError(
'Search path hits shape type {} from {}'.format(
shape.type_name, item
)
f'Search path hits shape type {shape.type_name} from {item}'
)

# Anything not handled here is set to None
Expand Down
1 change: 1 addition & 0 deletions boto3/s3/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __call__(self, bytes_amount):
"""

import logging
import threading
from os import PathLike, fspath, getpid
Expand Down
4 changes: 1 addition & 3 deletions boto3/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def __init__(

# Setup custom user-agent string if it isn't already customized
if self._session.user_agent_name == 'Botocore':
botocore_info = 'Botocore/{}'.format(
self._session.user_agent_version
)
botocore_info = f'Botocore/{self._session.user_agent_version}'
if self._session.user_agent_extra:
self._session.user_agent_extra += ' ' + botocore_info
else:
Expand Down
5 changes: 2 additions & 3 deletions scripts/new-change
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ You can then use the ``scripts/gen-changelog`` to generate the
CHANGELOG.rst file.
"""

import argparse
import json
import os
Expand Down Expand Up @@ -132,9 +133,7 @@ def replace_issue_references(parsed, repo_name):

def linkify(match):
number = match.group()[1:]
return '`{} <https://github.com/{}/issues/{}>`__'.format(
match.group(), repo_name, number
)
return f'`{match.group()} <https://github.com/{repo_name}/issues/{number}>`__'

new_description = re.sub(r'#\d+', linkify, description)
parsed['description'] = new_description
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
distutils/setuptools install script.
"""

import os
import re

Expand Down
8 changes: 4 additions & 4 deletions tests/functional/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def assert_contains_lines_in_order(self, lines, contents):
contents = contents[(beginning + len(line)) :]

def get_class_document_block(self, class_name, contents):
start_class_document = '.. py:class:: %s' % class_name
start_class_document = f'.. py:class:: {class_name}'
start_index = contents.find(start_class_document)
assert start_index != -1, 'Class is not found in contents'
contents = contents[start_index:]
end_index = contents.find(' .. py:class::', len(start_class_document))
return contents[:end_index]

def get_method_document_block(self, method_name, contents):
start_method_document = ' .. py:method:: %s(' % method_name
start_method_document = f' .. py:method:: {method_name}('
start_index = contents.find(start_method_document)
assert start_index != -1, 'Method is not found in contents'
contents = contents[start_index:]
Expand All @@ -68,7 +68,7 @@ def get_response_syntax_document_block(self, contents):
return contents[:end_index]

def get_request_parameter_document_block(self, param_name, contents):
start_param_document = ':type %s:' % param_name
start_param_document = f':type {param_name}:'
start_index = contents.find(start_param_document)
assert start_index != -1, 'Param is not found in contents'
contents = contents[start_index:]
Expand All @@ -80,7 +80,7 @@ def get_response_parameter_document_block(self, param_name, contents):
start_index = contents.find(start_param_document)
assert start_index != -1, 'There is no response structure'

start_param_document = '- **%s**' % param_name
start_param_document = f'- **{param_name}**'
start_index = contents.find(start_param_document)
assert start_index != -1, 'Param is not found in contents'
contents = contents[start_index:]
Expand Down
Loading

0 comments on commit 50d25e9

Please sign in to comment.