Skip to content

Commit 73ce98b

Browse files
authored
Enable Ruff N (pep8-naming) on non-stubs (#13327)
1 parent 67568b5 commit 73ce98b

5 files changed

Lines changed: 17 additions & 13 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ select = [
4141
"B", # flake8-bugbear
4242
"FA", # flake8-future-annotations
4343
"I", # isort
44+
"N", # pep8-naming
4445
"PGH", # pygrep-hooks
4546
"RUF", # Ruff-specific and unused-noqa
4647
"UP", # pyupgrade
@@ -118,6 +119,9 @@ ignore = [
118119
# See https://github.com/python/typeshed/pull/13108
119120
"RUF022",
120121
"RUF023",
122+
# Most pep8-naming rules don't apply for third-party stubs like typeshed.
123+
# N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one
124+
"N8",
121125
# Rules that are out of the control of stub authors:
122126
"F403", # `from . import *` used; unable to detect undefined names
123127
# Stubs can sometimes re-export entire modules.

scripts/stubsabot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,13 @@ def latest_commit_is_different_to_last_commit_on_origin(branch: str) -> bool:
632632
return True
633633

634634

635-
class RemoteConflict(Exception):
635+
class RemoteConflictError(Exception):
636636
pass
637637

638638

639639
def somewhat_safe_force_push(branch: str) -> None:
640640
if has_non_stubsabot_commits(branch):
641-
raise RemoteConflict(f"origin/{branch} has non-stubsabot changes that are not on {branch}!")
641+
raise RemoteConflictError(f"origin/{branch} has non-stubsabot changes that are not on {branch}!")
642642
subprocess.check_call(["git", "push", "origin", branch, "--force"])
643643

644644

@@ -808,7 +808,7 @@ async def main() -> None:
808808
if isinstance(update, Obsolete): # pyright: ignore[reportUnnecessaryIsInstance]
809809
await suggest_typeshed_obsolete(update, session, action_level=args.action_level)
810810
continue
811-
except RemoteConflict as e:
811+
except RemoteConflictError as e:
812812
print(colored(f"... but ran into {type(e).__qualname__}: {e}", "red"))
813813
continue
814814
raise AssertionError

scripts/sync_protobuf/google_protobuf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ def main() -> None:
6666
for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"):
6767
old_stub.unlink()
6868

69-
PROTOC_VERSION = run_protoc(
69+
protoc_version = run_protoc(
7070
proto_paths=(f"{EXTRACTED_PACKAGE_DIR}/src",),
7171
mypy_out=STUBS_FOLDER,
7272
proto_globs=extract_proto_file_paths(temp_dir),
7373
cwd=temp_dir,
7474
)
7575

76-
PYTHON_PROTOBUF_VERSION = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "version.json")
76+
python_protobuf_version = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "version.json")
7777

7878
# Cleanup after ourselves, this is a temp dir, but it can still grow fast if run multiple times
7979
shutil.rmtree(temp_dir)
@@ -82,9 +82,9 @@ def main() -> None:
8282
"protobuf",
8383
extra_description=f"""Partially generated using \
8484
[mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \
85-
and {PROTOC_VERSION} on \
85+
and {protoc_version} on \
8686
[protobuf v{PACKAGE_VERSION}](https://github.com/protocolbuffers/protobuf/releases/tag/v{PACKAGE_VERSION}) \
87-
(python `protobuf=={PYTHON_PROTOBUF_VERSION}`).""",
87+
(python `protobuf=={python_protobuf_version}`).""",
8888
)
8989
print("Updated protobuf/METADATA.toml")
9090

scripts/sync_protobuf/s2clientprotocol.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def main() -> None:
4646
for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"):
4747
old_stub.unlink()
4848

49-
PROTOC_VERSION = run_protoc(
49+
protoc_version = run_protoc(
5050
proto_paths=(EXTRACTED_PACKAGE_DIR,),
5151
mypy_out=STUBS_FOLDER,
5252
proto_globs=(f"{EXTRACTED_PACKAGE_DIR}/s2clientprotocol/*.proto",),
5353
cwd=temp_dir,
5454
)
5555

56-
PYTHON_S2_CLIENT_PROTO_VERSION = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "s2clientprotocol" / "build.py")
56+
python_s2_client_proto_version = extract_python_version(temp_dir / EXTRACTED_PACKAGE_DIR / "s2clientprotocol" / "build.py")
5757

5858
# Cleanup after ourselves, this is a temp dir, but it can still grow fast if run multiple times
5959
shutil.rmtree(temp_dir)
@@ -62,8 +62,8 @@ def main() -> None:
6262
"s2clientprotocol",
6363
extra_description=f"""Partially generated using \
6464
[mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \
65-
and {PROTOC_VERSION} on \
66-
[s2client-proto {PYTHON_S2_CLIENT_PROTO_VERSION}](https://github.com/Blizzard/s2client-proto/tree/{PACKAGE_VERSION}).""",
65+
and {protoc_version} on \
66+
[s2client-proto {python_s2_client_proto_version}](https://github.com/Blizzard/s2client-proto/tree/{PACKAGE_VERSION}).""",
6767
)
6868
print("Updated s2clientprotocol/METADATA.toml")
6969

scripts/sync_protobuf/tensorflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def main() -> None:
9999
for old_stub in STUBS_FOLDER.rglob("*_pb2.pyi"):
100100
old_stub.unlink()
101101

102-
PROTOC_VERSION = run_protoc(
102+
protoc_version = run_protoc(
103103
proto_paths=(
104104
f"{EXTRACTED_PACKAGE_DIR}/third_party/xla/third_party/tsl",
105105
f"{EXTRACTED_PACKAGE_DIR}/third_party/xla",
@@ -130,7 +130,7 @@ def main() -> None:
130130
"tensorflow",
131131
extra_description=f"""Partially generated using \
132132
[mypy-protobuf=={MYPY_PROTOBUF_VERSION}](https://github.com/nipunn1313/mypy-protobuf/tree/v{MYPY_PROTOBUF_VERSION}) \
133-
and {PROTOC_VERSION} on `tensorflow=={PACKAGE_VERSION}`.""",
133+
and {protoc_version} on `tensorflow=={PACKAGE_VERSION}`.""",
134134
)
135135
print("Updated tensorflow/METADATA.toml")
136136

0 commit comments

Comments
 (0)