diff --git a/pyproject.toml b/pyproject.toml index 3206d143e6d1..1caa7ee5d1b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ select = [ "B", # flake8-bugbear "FA", # flake8-future-annotations "I", # isort + "N", # pep8-naming "PGH", # pygrep-hooks "RUF", # Ruff-specific and unused-noqa "UP", # pyupgrade @@ -108,6 +109,9 @@ ignore = [ # See https://github.com/python/typeshed/pull/13108 "RUF022", "RUF023", + # Most pep8-naming rules don't apply for third-party stubs like typeshed. + # N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one + "N8", # Rules that are out of the control of stub authors: "F403", # `from . import *` used; unable to detect undefined names # Stubs can sometimes re-export entire modules. diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index aee09eb3e8a2..f121bed5f5f0 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -632,13 +632,13 @@ def latest_commit_is_different_to_last_commit_on_origin(branch: str) -> bool: return True -class RemoteConflict(Exception): +class RemoteConflictError(Exception): pass def somewhat_safe_force_push(branch: str) -> None: if has_non_stubsabot_commits(branch): - raise RemoteConflict(f"origin/{branch} has non-stubsabot changes that are not on {branch}!") + raise RemoteConflictError(f"origin/{branch} has non-stubsabot changes that are not on {branch}!") subprocess.check_call(["git", "push", "origin", branch, "--force"]) @@ -808,7 +808,7 @@ async def main() -> None: if isinstance(update, Obsolete): # pyright: ignore[reportUnnecessaryIsInstance] await suggest_typeshed_obsolete(update, session, action_level=args.action_level) continue - except RemoteConflict as e: + except RemoteConflictError as e: print(colored(f"... but ran into {type(e).__qualname__}: {e}", "red")) continue raise AssertionError diff --git a/scripts/sync_protobuf/google_protobuf.py b/scripts/sync_protobuf/google_protobuf.py index da2ced6f9fc7..1abab24c51a4 100644 --- a/scripts/sync_protobuf/google_protobuf.py +++ b/scripts/sync_protobuf/google_protobuf.py @@ -66,14 +66,14 @@ def main() -> None: for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"): old_stub.unlink() - PROTOC_VERSION = run_protoc( + protoc_version = run_protoc( proto_paths=(f"{EXTRACTED_PACKAGE_DIR}/src",), mypy_out=STUBS_FOLDER, proto_globs=extract_proto_file_paths(temp_dir), cwd=temp_dir, ) - PYTHON_PROTOBUF_VERSION = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "version.json") + python_protobuf_version = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "version.json") # Cleanup after ourselves, this is a temp dir, but it can still grow fast if run multiple times shutil.rmtree(temp_dir) @@ -82,9 +82,9 @@ def main() -> None: "protobuf", extra_description=f"""Partially generated using \ [mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \ -and {PROTOC_VERSION} on \ +and {protoc_version} on \ [protobuf v{PACKAGE_VERSION}](https://github.com/protocolbuffers/protobuf/releases/tag/v{PACKAGE_VERSION}) \ -(python `protobuf=={PYTHON_PROTOBUF_VERSION}`).""", +(python `protobuf=={python_protobuf_version}`).""", ) print("Updated protobuf/METADATA.toml") diff --git a/scripts/sync_protobuf/s2clientprotocol.py b/scripts/sync_protobuf/s2clientprotocol.py index 8f86fe5dccdd..365eb0309371 100644 --- a/scripts/sync_protobuf/s2clientprotocol.py +++ b/scripts/sync_protobuf/s2clientprotocol.py @@ -46,14 +46,14 @@ def main() -> None: for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"): old_stub.unlink() - PROTOC_VERSION = run_protoc( + protoc_version = run_protoc( proto_paths=(EXTRACTED_PACKAGE_DIR,), mypy_out=STUBS_FOLDER, proto_globs=(f"{EXTRACTED_PACKAGE_DIR}/s2clientprotocol/*.proto",), cwd=temp_dir, ) - PYTHON_S2_CLIENT_PROTO_VERSION = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "s2clientprotocol" / "build.py") + python_s2_client_proto_version = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "s2clientprotocol" / "build.py") # Cleanup after ourselves, this is a temp dir, but it can still grow fast if run multiple times shutil.rmtree(temp_dir) @@ -62,8 +62,8 @@ def main() -> None: "s2clientprotocol", extra_description=f"""Partially generated using \ [mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \ -and {PROTOC_VERSION} on \ -[s2client-proto {PYTHON_S2_CLIENT_PROTO_VERSION}](https://github.com/Blizzard/s2client-proto/tree/{PACKAGE_VERSION}).""", +and {protoc_version} on \ +[s2client-proto {python_s2_client_proto_version}](https://github.com/Blizzard/s2client-proto/tree/{PACKAGE_VERSION}).""", ) print("Updated s2clientprotocol/METADATA.toml") diff --git a/scripts/sync_protobuf/tensorflow.py b/scripts/sync_protobuf/tensorflow.py index 8328ca2c0e09..e4af065030c3 100644 --- a/scripts/sync_protobuf/tensorflow.py +++ b/scripts/sync_protobuf/tensorflow.py @@ -99,7 +99,7 @@ def main() -> None: for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"): old_stub.unlink() - PROTOC_VERSION = run_protoc( + protoc_version = run_protoc( proto_paths=( f"{EXTRACTED_PACKAGE_DIR}/third_party/xla/third_party/tsl", f"{EXTRACTED_PACKAGE_DIR}/third_party/xla", @@ -130,7 +130,7 @@ def main() -> None: "tensorflow", extra_description=f"""Partially generated using \ [mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \ -and {PROTOC_VERSION} on `tensorflow=={PACKAGE_VERSION}`.""", +and {protoc_version} on `tensorflow=={PACKAGE_VERSION}`.""", ) print("Updated tensorflow/METADATA.toml")