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

Enable Ruff RET (flake8-return) #13323

Open
wants to merge 3 commits into
base: main
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
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ select = [
"FA", # flake8-future-annotations
"I", # isort
"PGH", # pygrep-hooks
"RET", # flake8-return
"RUF", # Ruff-specific and unused-noqa
"UP", # pyupgrade
"YTT", # flake8-2020
Expand Down Expand Up @@ -89,11 +90,16 @@ ignore = [
###
# Rules we don't want or don't agree with
###
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
# Used for direct, non-subclass type comparison, for example: `type(val) is str`
# see https://github.com/astral-sh/ruff/issues/6465
"E721", # Do not compare types, use `isinstance()`
# `else` can be clearer to read, especially for short branches or elif chains
"RET505", # Unnecessary `{branch}` after `return` statement
"RET506", # Unnecessary `{branch}` after `raise` statement
"RET507", # Unnecessary `{branch}` after `continue` statement
"RET508", # Unnecessary `{branch}` after `break` statement
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
###
# False-positives, but already checked by type-checkers
###
Expand Down
3 changes: 1 addition & 2 deletions scripts/sync_protobuf/google_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ def extract_proto_file_paths(temp_dir: Path) -> list[str]:
"""
with open(temp_dir / EXTRACTED_PACKAGE_DIR / "python" / "dist" / "BUILD.bazel") as file:
matched_lines = filter(None, (re.search(PROTO_FILE_PATTERN, line) for line in file))
proto_files = [
return [
EXTRACTED_PACKAGE_DIR + "/src/google/protobuf/" + match.group(1).replace("compiler_", "compiler/") + ".proto"
for match in matched_lines
]
return proto_files


def main() -> None:
Expand Down
3 changes: 1 addition & 2 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def _parse_jsonc(json_text: str) -> str:
# strip comments from the file
lines = [line for line in json_text.split("\n") if not line.strip().startswith("//")]
# strip trailing commas from the file
valid_json = re.sub(r",(\s*?[\}\]])", r"\1", "\n".join(lines))
return valid_json
return re.sub(r",(\s*?[\}\]])", r"\1", "\n".join(lines))


def _get_strict_params(stub_path: str) -> list[str]:
Expand Down
Loading