diff --git a/pyproject.toml b/pyproject.toml index abd6dfec..b6b6c52a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,8 +43,8 @@ dev = [ "pytest-timeout ~= 2.3.0", "pytest-xdist ~= 3.6.0", "redbaron ~= 0.9.0", - "ruff ~= 0.4.0", - "setuptools ~= 70.0.0", # setuptools are used by pytest, but not explicitly required + "ruff ~= 0.5.0", + "setuptools ~= 70.3.0", # setuptools are used by pytest, but not explicitly required "twine ~= 5.1.0", ] @@ -57,7 +57,7 @@ dev = [ "Apify Homepage" = "https://apify.com" [build-system] -requires = ["setuptools ~= 70.0.0", "wheel"] +requires = ["setuptools ~= 70.3.0", "wheel"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] @@ -69,6 +69,8 @@ apify_client = ["py.typed"] [tool.ruff] line-length = 150 + +[tool.ruff.lint] select = ["ALL"] ignore = [ "ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {filename} diff --git a/scripts/fix_async_docstrings.py b/scripts/fix_async_docstrings.py index da441ce2..1b7aad4c 100755 --- a/scripts/fix_async_docstrings.py +++ b/scripts/fix_async_docstrings.py @@ -42,7 +42,7 @@ continue # Work around a bug in Red Baron, which indents docstrings too much when you insert them, so we have to un-indent it one level first - correct_async_docstring = re.sub('^ ', '', correct_async_docstring, flags=re.M) + correct_async_docstring = re.sub('^ ', '', correct_async_docstring, flags=re.MULTILINE) if not isinstance(async_docstring, str): print(f'Fixing missing docstring for "{async_class.name}.{async_method.name}"...') @@ -54,14 +54,14 @@ # Work around a bug in Red Baron, which adds indents to docstrings when you insert them (including empty lines), # so we have to remove the extra whitespace - updated_source_code = re.sub('^ $', '', updated_source_code, flags=re.M) + updated_source_code = re.sub('^ $', '', updated_source_code, flags=re.MULTILINE) # Work around a bug in Red Baron, which indents `except` and `finally` statements wrong # so we have to add some extra whitespace - updated_source_code = re.sub('^except', ' except', updated_source_code, flags=re.M) - updated_source_code = re.sub('^ except', ' except', updated_source_code, flags=re.M) - updated_source_code = re.sub('^finally', ' finally', updated_source_code, flags=re.M) - updated_source_code = re.sub('^ finally', ' finally', updated_source_code, flags=re.M) + updated_source_code = re.sub('^except', ' except', updated_source_code, flags=re.MULTILINE) + updated_source_code = re.sub('^ except', ' except', updated_source_code, flags=re.MULTILINE) + updated_source_code = re.sub('^finally', ' finally', updated_source_code, flags=re.MULTILINE) + updated_source_code = re.sub('^ finally', ' finally', updated_source_code, flags=re.MULTILINE) # Work around a bug in Red Baron, which sometimes adds an extra new line to the end of a file updated_source_code = updated_source_code.rstrip() + '\n' diff --git a/scripts/utils.py b/scripts/utils.py index 78a61e86..7eb07a8a 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -48,7 +48,7 @@ def sync_to_async_docstring(docstring: str) -> str: substitutions = [(r'Client', r'ClientAsync')] res = docstring for pattern, replacement in substitutions: - res = re.sub(pattern, replacement, res, flags=re.M) + res = re.sub(pattern, replacement, res, flags=re.MULTILINE) return res diff --git a/src/apify_client/_errors.py b/src/apify_client/_errors.py index 2f19749a..d5b2f528 100644 --- a/src/apify_client/_errors.py +++ b/src/apify_client/_errors.py @@ -72,9 +72,14 @@ def __init__(self: InvalidResponseBodyError, response: httpx.Response) -> None: self.response = response -def is_retryable_error(e: Exception) -> bool: +def is_retryable_error(exc: Exception) -> bool: """Check if the given error is retryable.""" - if isinstance(e, (InvalidResponseBodyError, httpx.NetworkError, httpx.TimeoutException, httpx.RemoteProtocolError)): - return True - - return False + return isinstance( + exc, + ( + InvalidResponseBodyError, + httpx.NetworkError, + httpx.TimeoutException, + httpx.RemoteProtocolError, + ), + ) diff --git a/src/apify_client/_logging.py b/src/apify_client/_logging.py index aa7d6408..3fbefb2f 100644 --- a/src/apify_client/_logging.py +++ b/src/apify_client/_logging.py @@ -109,7 +109,7 @@ def _get_extra_fields(self: _DebugLogFormatter, record: logging.LogRecord) -> di extra_fields: dict = {} for key, value in record.__dict__.items(): if key not in self.empty_record.__dict__: - extra_fields[key] = value + extra_fields[key] = value # noqa: PERF403 return extra_fields