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

Upgrade ruff, fix issues, use ruff for import sorting #3380

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: 'https://github.com/PyCQA/isort'
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.9.4
hooks:
- id: ruff
args: [ --fix ]
Expand Down
7 changes: 2 additions & 5 deletions botocore/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from botocore.compat import (
HAS_CRT,
MD5_AVAILABLE, # noqa: F401 -- keep imported for backwards compatibility
HTTPHeaders,
encodebytes,
ensure_unicode,
Expand All @@ -47,10 +48,6 @@
percent_encode_sequence,
)

# Imports for backwards compatibility
from botocore.compat import MD5_AVAILABLE # noqa


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -88,7 +85,7 @@ def _host_from_url(url):
}
if url_parts.port is not None:
if url_parts.port != default_ports.get(url_parts.scheme):
host = '%s:%d' % (host, url_parts.port)
host = f'{host}:{url_parts.port}'
return host


Expand Down
25 changes: 11 additions & 14 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# language governing permissions and limitations under the License.
import logging

from botocore import waiter, xform_name
from botocore import (
UNSIGNED, # noqa: F401 -- keep imported for backwards compatibility
waiter,
xform_name,
)
from botocore.args import ClientArgsCreator
from botocore.auth import AUTH_TYPE_MAPS, resolve_auth_type
from botocore.awsrequest import prepare_request_dict
Expand All @@ -26,6 +30,7 @@
)
from botocore.docs.docstring import ClientMethodDocstring, PaginatorDocstring
from botocore.exceptions import (
ClientError, # noqa: F401 -- keep imported for backwards compatibility
DataNotFoundError,
InvalidEndpointDiscoveryConfigurationError,
OperationNotPageableError,
Expand All @@ -45,26 +50,18 @@
from botocore.utils import (
CachedProperty,
EventbridgeSignerSetter,
S3ArnParamHandler, # noqa: F401 -- keep imported for backwards compatibility
S3ControlArnParamHandler, # noqa: F401 -- keep imported for backwards compatibility
S3ControlArnParamHandlerv2,
S3ControlEndpointSetter, # noqa: F401 -- keep imported for backwards compatibility
S3EndpointSetter, # noqa: F401 -- keep imported for backwards compatibility
S3ExpressIdentityResolver,
S3RegionRedirector, # noqa: F401 -- keep imported for backwards compatibility
S3RegionRedirectorv2,
ensure_boolean,
get_service_module_name,
)

# Keep these imported. There's pre-existing code that uses:
# "from botocore.client import UNSIGNED"
# "from botocore.client import ClientError"
# etc.
from botocore.exceptions import ClientError # noqa
from botocore.utils import S3ArnParamHandler # noqa
from botocore.utils import S3ControlArnParamHandler # noqa
from botocore.utils import S3ControlEndpointSetter # noqa
from botocore.utils import S3EndpointSetter # noqa
from botocore.utils import S3RegionRedirector # noqa
from botocore import UNSIGNED # noqa


_LEGACY_SIGNATURE_VERSIONS = frozenset(
(
'v2',
Expand Down
3 changes: 1 addition & 2 deletions botocore/docs/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ def _add_member_documentation(self, section, shape, name=None, **kwargs):
[f'``{key}``' for key in shape.members.keys()]
)
unknown_code_example = (
'\'SDK_UNKNOWN_MEMBER\': '
'{\'name\': \'UnknownMemberName\'}'
'\'SDK_UNKNOWN_MEMBER\': {\'name\': \'UnknownMemberName\'}'
)
tagged_union_docs.write(note % (tagged_union_members_str))
example = section.add_new_section('param-unknown-example')
Expand Down
9 changes: 3 additions & 6 deletions botocore/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class ValidationError(BotoCoreError):
:ivar type_name: The name of the underlying type.
"""

fmt = "Invalid value ('{value}') for param {param} " "of type {type_name} "
fmt = "Invalid value ('{value}') for param {param} of type {type_name} "


class ParamValidationError(BotoCoreError):
Expand All @@ -371,8 +371,7 @@ class UnknownKeyError(ValidationError):
"""

fmt = (
"Unknown key '{value}' for param '{param}'. Must be one "
"of: {choices}"
"Unknown key '{value}' for param '{param}'. Must be one of: {choices}"
)


Expand Down Expand Up @@ -482,9 +481,7 @@ def __init__(self, name, reason, last_response):
class IncompleteReadError(BotoCoreError):
"""HTTP response did not return expected number of bytes."""

fmt = (
'{actual_bytes} read, but total bytes ' 'expected is {expected_bytes}.'
)
fmt = '{actual_bytes} read, but total bytes expected is {expected_bytes}.'


class InvalidExpressionError(BotoCoreError):
Expand Down
21 changes: 10 additions & 11 deletions botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@

import botocore
import botocore.auth
from botocore import utils
from botocore import (
retryhandler, # noqa: F401 -- keep imported for backwards compatibility
translate, # noqa: F401 -- keep imported for backwards compatibility
utils,
)
from botocore.compat import (
MD5_AVAILABLE, # noqa: F401 -- keep imported for backwards compatibility
ETree,
OrderedDict,
XMLParseError,
Expand All @@ -49,6 +54,7 @@
from botocore.endpoint_provider import VALID_HOST_LABEL_RE
from botocore.exceptions import (
AliasConflictParameterError,
MissingServiceIdError, # noqa: F401 -- keep imported for backwards compatibility
ParamValidationError,
UnsupportedTLSVersionWarning,
)
Expand All @@ -61,21 +67,14 @@
)
from botocore.utils import (
SAFE_CHARS,
SERVICE_NAME_ALIASES, # noqa: F401 -- keep imported for backwards compatibility
ArnParser,
hyphenize_service_id, # noqa: F401 -- keep imported for backwards compatibility
is_global_accesspoint, # noqa: F401 -- keep imported for backwards compatibility
percent_encode,
switch_host_with_param,
)

# Keep these imported. There's pre-existing code that uses them.
from botocore import retryhandler # noqa
from botocore import translate # noqa
from botocore.compat import MD5_AVAILABLE # noqa
from botocore.exceptions import MissingServiceIdError # noqa
from botocore.utils import hyphenize_service_id # noqa
from botocore.utils import is_global_accesspoint # noqa
from botocore.utils import SERVICE_NAME_ALIASES # noqa


logger = logging.getLogger(__name__)

REGISTER_FIRST = object()
Expand Down
2 changes: 1 addition & 1 deletion botocore/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def _get_auth_match(self, auth_val):
def _truncate(self, text, max_length):
if len(text) > max_length:
logger.debug(
'Truncating following value to maximum length of ' '%s: %s',
'Truncating following value to maximum length of %s: %s',
text,
max_length,
)
Expand Down
3 changes: 1 addition & 2 deletions botocore/paginate.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def __iter__(self):
and previous_next_token == next_token
):
message = (
f"The same next token was received "
f"twice: {next_token}"
f"The same next token was received twice: {next_token}"
)
raise PaginationError(message=message)
self._inject_token_into_kwargs(current_kwargs, next_token)
Expand Down
19 changes: 11 additions & 8 deletions botocore/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
from urllib3.exceptions import ProtocolError as URLLib3ProtocolError
from urllib3.exceptions import ReadTimeoutError as URLLib3ReadTimeoutError

from botocore import parsers
from botocore.compat import set_socket_timeout
from botocore import (
ScalarTypes, # noqa: F401 -- keep imported for backwards compatibility
parsers,
)
from botocore.compat import (
XMLParseError, # noqa: F401 -- keep imported for backwards compatibility
set_socket_timeout,
)
from botocore.exceptions import (
IncompleteReadError,
ReadTimeoutError,
ResponseStreamingError,
)

# Keep these imported. There's pre-existing code that uses them.
from botocore import ScalarTypes # noqa
from botocore.compat import XMLParseError # noqa
from botocore.hooks import first_non_none_response # noqa

from botocore.hooks import (
first_non_none_response, # noqa: F401 -- keep imported for backwards compatibility
)

logger = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions botocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
translate,
waiter,
)
from botocore.compat import HAS_CRT, MutableMapping
from botocore.compat import (
HAS_CRT, # noqa: F401 -- keep imported for backwards compatibility
MutableMapping,
)
from botocore.configprovider import (
BOTOCORE_DEFAUT_SESSION_VARIABLES,
ConfigChainFactory,
Expand Down Expand Up @@ -72,9 +75,6 @@
validate_region_name,
)

from botocore.compat import HAS_CRT # noqa


logger = logging.getLogger(__name__)


Expand Down
9 changes: 5 additions & 4 deletions botocore/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
UnknownSignatureVersionError,
UnsupportedSignatureVersionError,
)
from botocore.utils import ArnParser, datetime2timestamp

# Keep these imported. There's pre-existing code that uses them.
from botocore.utils import fix_s3_host # noqa
from botocore.utils import (
ArnParser,
datetime2timestamp,
fix_s3_host, # noqa: F401 -- keep imported for backwards compatibility
)


class RequestSigner:
Expand Down
21 changes: 9 additions & 12 deletions botocore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@
import botocore
import botocore.awsrequest
import botocore.httpsession

# IP Regexes retained for backwards compatibility
from botocore.compat import HEX_PAT # noqa: F401
from botocore.compat import IPV4_PAT # noqa: F401
from botocore.compat import IPV6_ADDRZ_PAT # noqa: F401
from botocore.compat import IPV6_PAT # noqa: F401
from botocore.compat import LS32_PAT # noqa: F401
from botocore.compat import UNRESERVED_PAT # noqa: F401
from botocore.compat import ZONE_ID_PAT # noqa: F401
from botocore.compat import (
HAS_CRT,
HEX_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
IPV4_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
IPV4_RE,
IPV6_ADDRZ_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
IPV6_ADDRZ_RE,
IPV6_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
LS32_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
MD5_AVAILABLE,
UNRESERVED_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
UNSAFE_URL_CHARS,
ZONE_ID_PAT, # noqa: F401 -- IP Regexes retained for backwards compatibility
OrderedDict,
get_md5,
get_tzinfo_options,
Expand Down Expand Up @@ -681,7 +679,7 @@ def _evaluate_expiration(self, credentials):
f"Attempting credential expiration extension due to a "
f"credential service availability issue. A refresh of "
f"these credentials will be attempted again within "
f"the next {refresh_interval_with_jitter/60:.0f} minutes."
f"the next {refresh_interval_with_jitter / 60:.0f} minutes."
)
except ValueError:
logger.debug(
Expand Down Expand Up @@ -3532,8 +3530,7 @@ def __setitem__(self, cache_key, value):
file_content = self._dumps(value)
except (TypeError, ValueError):
raise ValueError(
f"Value cannot be cached, must be "
f"JSON serializable: {value}"
f"Value cannot be cached, must be JSON serializable: {value}"
)
if not os.path.isdir(self._working_dir):
os.makedirs(self._working_dir)
Expand Down
2 changes: 1 addition & 1 deletion botocore/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _validate_document(self, params, shape, errors, name):
elif isinstance(params, list):
for index, entity in enumerate(params):
self._validate_document(
entity, shape, errors, '%s[%d]' % (name, index)
entity, shape, errors, f'{name}[{index}]'
)
elif not isinstance(params, ((str,), int, bool, float)):
valid_types = (str, int, bool, float, list, dict)
Expand Down
2 changes: 1 addition & 1 deletion botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def wait(self, **kwargs):
)
if current_state == 'success':
logger.debug(
"Waiting complete, waiter matched the " "success state."
"Waiting complete, waiter matched the success state."
)
return
if current_state == 'failure':
Expand Down
18 changes: 11 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ markers = [
"validates_models: marks tests as one which validates service models",
]

[tool.isort]
profile = "black"
line_length = 79
honor_noqa = true
src_paths = ["botocore", "tests"]

[tool.ruff]
exclude = [
".bzr",
".changes", # from .pre-commit-config.yaml
".direnv",
".eggs",
".git",
".git-rewrite",
".github", # from .pre-commit-config.yaml
".hg",
".ipynb_checkpoints",
".mypy_cache",
Expand All @@ -32,11 +28,19 @@ exclude = [
".vscode",
"__pypackages__",
"_build",
"botocore/compat.py", # from .pre-commit-config.yaml
"botocore/data", # from .pre-commit-config.yaml
"botocore/vendored", # from .pre-commit-config.yaml
"buck-out",
"build",
"dist",
"docs/", # from .pre-commit-config.yaml
"node_modules",
"site-packages",
"tests/functional/endpoint-rules", # from .pre-commit-config.yaml
"tests/unit/auth/aws4_testsuite", # from .pre-commit-config.yaml
"tests/unit/data/endpoints/", # from .pre-commit-config.yaml
"tests/unit/response_parsing/xml", # from .pre-commit-config.yaml
"venv",
]

Expand All @@ -50,7 +54,7 @@ target-version = "py38"
# 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", "UP"]
select = ["E4", "E7", "E9", "F", "UP", "I"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-model-filename
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def main():
return 0
if len(args) != 1:
sys.stderr.write(
"Must provide the filename of the JSON model " "as an argument.\n"
"Must provide the filename of the JSON model as an argument.\n"
)
return 1
source_filename = args[0]
Expand Down
Loading
Loading