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 14, 2024
1 parent 54451db commit 5b9a349
Show file tree
Hide file tree
Showing 47 changed files with 182 additions and 267 deletions.
1 change: 1 addition & 0 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
considered internal, and *not* a public API.
"""

import copy
import logging
import socket
Expand Down
13 changes: 3 additions & 10 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,7 @@ def _make_api_call(self, operation_name, api_params):

service_id = self._service_model.service_id.hyphenize()
handler, event_response = self.meta.events.emit_until_response(
'before-call.{service_id}.{operation_name}'.format(
service_id=service_id, operation_name=operation_name
),
f'before-call.{service_id}.{operation_name}',
model=operation_model,
params=request_dict,
request_signer=self._request_signer,
Expand All @@ -1003,9 +1001,7 @@ def _make_api_call(self, operation_name, api_params):
)

self.meta.events.emit(
'after-call.{service_id}.{operation_name}'.format(
service_id=service_id, operation_name=operation_name
),
f'after-call.{service_id}.{operation_name}',
http_response=http,
parsed=parsed_response,
model=operation_model,
Expand All @@ -1027,10 +1023,7 @@ def _make_request(self, operation_model, request_dict, request_context):
return self._endpoint.make_request(operation_model, request_dict)
except Exception as e:
self.meta.events.emit(
'after-call-error.{service_id}.{operation_name}'.format(
service_id=self._service_model.service_id.hyphenize(),
operation_name=operation_model.name,
),
f'after-call-error.{self._service_model.service_id.hyphenize()}.{operation_model.name}',
exception=e,
context=request_context,
)
Expand Down
11 changes: 3 additions & 8 deletions botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""This module contains the interface for controlling how configuration
is loaded.
"""

import copy
import logging
import os
Expand Down Expand Up @@ -728,10 +729,7 @@ def provide(self):
return value

def __repr__(self):
return 'InstanceVarProvider(instance_var={}, session={})'.format(
self._instance_var,
self._session,
)
return f'InstanceVarProvider(instance_var={self._instance_var}, session={self._session})'


class ScopedConfigProvider(BaseProvider):
Expand Down Expand Up @@ -767,10 +765,7 @@ def provide(self):
return scoped_config.get(self._config_var_name)

def __repr__(self):
return 'ScopedConfigProvider(config_var_name={}, session={})'.format(
self._config_var_name,
self._session,
)
return f'ScopedConfigProvider(config_var_name={self._config_var_name}, session={self._session})'


class EnvironmentProvider(BaseProvider):
Expand Down
4 changes: 1 addition & 3 deletions botocore/docs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def _add_client_creation_example(self, section):
section.style.start_codeblock()
section.style.new_line()
section.write(
'client = session.create_client(\'{service}\')'.format(
service=self._service_name
)
f'client = session.create_client(\'{self._service_name}\')'
)
section.style.end_codeblock()

Expand Down
4 changes: 1 addition & 3 deletions botocore/docs/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ def document_paginate_method(

paginate_description = (
'Creates an iterator that will paginate through responses '
'from :py:meth:`{}.Client.{}`.'.format(
get_service_module_name(service_model), xform_name(paginator_name)
)
f'from :py:meth:`{get_service_module_name(service_model)}.Client.{xform_name(paginator_name)}`.'
)

document_model_driven_method(
Expand Down
14 changes: 5 additions & 9 deletions botocore/docs/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def document_wait_method(
type_name='integer',
documentation=(
'<p>The amount of time in seconds to wait between '
'attempts. Default: {}</p>'.format(waiter_model.delay)
f'attempts. Default: {waiter_model.delay}</p>'
),
)

Expand All @@ -144,7 +144,7 @@ def document_wait_method(
type_name='integer',
documentation=(
'<p>The maximum number of attempts to be made. '
'Default: {}</p>'.format(waiter_model.max_attempts)
f'Default: {waiter_model.max_attempts}</p>'
),
)

Expand All @@ -161,14 +161,10 @@ def document_wait_method(
]

wait_description = (
'Polls :py:meth:`{}.Client.{}` every {} '
f'Polls :py:meth:`{get_service_module_name(service_model)}.Client.'
f'{xform_name(waiter_model.operation)}` every {waiter_model.delay} '
'seconds until a successful state is reached. An error is '
'returned after {} failed checks.'.format(
get_service_module_name(service_model),
xform_name(waiter_model.operation),
waiter_model.delay,
waiter_model.max_attempts,
)
f'returned after {waiter_model.max_attempts} failed checks.'
)

document_model_driven_method(
Expand Down
16 changes: 7 additions & 9 deletions botocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ def create_request(self, params, operation_model=None):
]
)
service_id = operation_model.service_model.service_id.hyphenize()
event_name = 'request-created.{service_id}.{op_name}'.format(
service_id=service_id, op_name=operation_model.name
)
event_name = f'request-created.{service_id}.{operation_model.name}'
self._event_emitter.emit(
event_name,
request=request,
Expand Down Expand Up @@ -224,9 +222,9 @@ def _send_request(self, request_dict, operation_model):
):
# We want to share num retries, not num attempts.
total_retries = attempts - 1
success_response[1]['ResponseMetadata'][
'RetryAttempts'
] = total_retries
success_response[1]['ResponseMetadata']['RetryAttempts'] = (
total_retries
)
if exception is not None:
raise exception
else:
Expand Down Expand Up @@ -298,9 +296,9 @@ def _do_get_response(self, request, operation_model, context):
)

http_response_record_dict = response_dict.copy()
http_response_record_dict[
'streaming'
] = operation_model.has_streaming_output
http_response_record_dict['streaming'] = (
operation_model.has_streaming_output
)
history_recorder.record('HTTP_RESPONSE', http_response_record_dict)

protocol = operation_model.metadata['protocol']
Expand Down
1 change: 0 additions & 1 deletion botocore/endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
or you can look at the test files in /tests/unit/data/endpoints/valid-rules/
"""


import logging
import re
from enum import Enum
Expand Down
4 changes: 2 additions & 2 deletions botocore/errorfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def __getattr__(self, name):
for exception_cls in self._code_to_exception.values()
]
raise AttributeError(
fr"{self} object has no attribute {name}. "
fr"Valid exceptions are: {', '.join(exception_cls_names)}"
rf"{self} object has no attribute {name}. "
rf"Valid exceptions are: {', '.join(exception_cls_names)}"
)


Expand Down
19 changes: 4 additions & 15 deletions botocore/eventstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Binary Event Stream Decoding """
"""Binary Event Stream Decoding"""

from binascii import crc32
from struct import unpack
Expand Down Expand Up @@ -41,34 +41,23 @@ class InvalidHeadersLength(ParserError):
"""Headers length is longer than the maximum."""

def __init__(self, length):
message = 'Header length of {} exceeded the maximum of {}'.format(
length,
_MAX_HEADERS_LENGTH,
)
message = f'Header length of {length} exceeded the maximum of {_MAX_HEADERS_LENGTH}'
super().__init__(message)


class InvalidPayloadLength(ParserError):
"""Payload length is longer than the maximum."""

def __init__(self, length):
message = 'Payload length of {} exceeded the maximum of {}'.format(
length,
_MAX_PAYLOAD_LENGTH,
)
message = f'Payload length of {length} exceeded the maximum of {_MAX_PAYLOAD_LENGTH}'
super().__init__(message)


class ChecksumMismatch(ParserError):
"""Calculated checksum did not match the expected checksum."""

def __init__(self, expected, calculated):
message = (
'Checksum mismatch: expected 0x{:08x}, calculated 0x{:08x}'.format(
expected,
calculated,
)
)
message = f'Checksum mismatch: expected 0x{expected:08x}, calculated 0x{calculated:08x}'
super().__init__(message)


Expand Down
3 changes: 2 additions & 1 deletion botocore/httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

""" The interfaces in this module are not intended for public use.
"""The interfaces in this module are not intended for public use.
This module defines interfaces for applying checksums to HTTP requests within
the context of botocore. This involves both resolving the checksum to be used
based on client configuration and environment, as well as application of the
checksum to the request.
"""

import base64
import io
import logging
Expand Down
1 change: 1 addition & 0 deletions botocore/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
for the sdk. For instance, additional operation parameters might be added here
which don't represent the actual service api.
"""

import logging
import os

Expand Down
1 change: 1 addition & 0 deletions botocore/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Abstractions to interact with service models."""

from collections import defaultdict
from typing import NamedTuple, Union

Expand Down
1 change: 1 addition & 0 deletions botocore/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
}
"""

import base64
import http.client
import json
Expand Down
1 change: 1 addition & 0 deletions botocore/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
given service and region and resolving the available endpoints for a service
in a specific AWS partition.
"""

import copy
import logging
import re
Expand Down
1 change: 1 addition & 0 deletions botocore/retries/bucket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module implements token buckets used for client side throttling."""

import threading
import time

Expand Down
4 changes: 1 addition & 3 deletions botocore/retries/quota.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Retry quota implementation.
"""Retry quota implementation."""

"""
import threading


Expand Down
1 change: 1 addition & 0 deletions botocore/retries/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module. Ideally we should be able to remove this module.
"""

import logging
from binascii import crc32

Expand Down
1 change: 1 addition & 0 deletions botocore/retries/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
based API used by botocore.
"""

import logging
import random

Expand Down
6 changes: 3 additions & 3 deletions botocore/retryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ def __call__(
if attempt_number >= self._max_attempts:
# explicitly set MaxAttemptsReached
if response is not None and 'ResponseMetadata' in response[1]:
response[1]['ResponseMetadata'][
'MaxAttemptsReached'
] = True
response[1]['ResponseMetadata']['MaxAttemptsReached'] = (
True
)
logger.debug(
"Reached the maximum number of retry attempts: %s",
attempt_number,
Expand Down
1 change: 1 addition & 0 deletions botocore/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
with the exception of blob types. Those are assumed to be binary,
and if a str/unicode type is passed in, it will be encoded as utf-8.
"""

import base64
import calendar
import datetime
Expand Down
8 changes: 2 additions & 6 deletions botocore/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def sign(

# Allow mutating request before signing
self._event_emitter.emit(
'before-sign.{}.{}'.format(
self._service_id.hyphenize(), operation_name
),
f'before-sign.{self._service_id.hyphenize()}.{operation_name}',
request=request,
signing_name=signing_name,
region_name=self._region_name,
Expand Down Expand Up @@ -231,9 +229,7 @@ def _choose_signer(self, operation_name, signing_type, context):
signature_version += suffix

handler, response = self._event_emitter.emit_until_response(
'choose-signer.{}.{}'.format(
self._service_id.hyphenize(), operation_name
),
f'choose-signer.{self._service_id.hyphenize()}.{operation_name}',
signing_name=signing_name,
region_name=region_name,
signature_version=signature_version,
Expand Down
1 change: 1 addition & 0 deletions botocore/useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* The ``user_agent_extra`` field in the :py:class:`botocore.config.Config`.
"""

import os
import platform
from copy import copy
Expand Down
5 changes: 1 addition & 4 deletions botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ def __init__(self, config):
@property
def explanation(self):
if self.matcher == 'path':
return 'For expression "{}" we matched expected path: "{}"'.format(
self.argument,
self.expected,
)
return f'For expression "{self.argument}" we matched expected path: "{self.expected}"'
elif self.matcher == 'pathAll':
return (
'For expression "%s" all members matched excepted path: "%s"'
Expand Down
Loading

0 comments on commit 5b9a349

Please sign in to comment.