Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff #4161

Merged
merged 2 commits into from
Jun 11, 2024
Merged

Ruff #4161

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: 'https://github.com/asottile/pyupgrade'
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
hooks:
- id: pyupgrade
args:
- '--py38-plus'
- repo: 'https://github.com/PyCQA/isort'
rev: 5.12.0
hooks:
- id: isort
- repo: 'https://github.com/psf/black'
rev: 23.11.0
hooks:
- id: black
- repo: 'https://github.com/pycqa/flake8'
rev: 6.1.0
hooks:
- id: flake8
- id: ruff
args: [ --fix ]
- id: ruff-format
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
65 changes: 58 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,63 @@ markers = [
"slow: marks tests as slow",
]

[tool.isort]
profile = "black"
line_length = 79
honor_noqa = true
src_paths = ["boto3", "tests"]
[tool.ruff]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

[tool.black]
# Format same as Black.
line-length = 79
skip_string_normalization = true
indent-width = 4

target-version = "py38"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "I", "UP"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings, spaces for indents
# and trailing commas.
quote-style = "preserve"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

docstring-code-format = false
docstring-code-line-length = "dynamic"
Loading
Loading