From dc6081431da1a864ed0426004e7f640f21bac448 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 28 Dec 2024 18:07:02 -0500 Subject: [PATCH 1/6] Enable Ruff D (pycodestyle) with pep257 convention --- lib/ts_utils/metadata.py | 7 ++++--- lib/ts_utils/utils.py | 1 - pyproject.toml | 20 ++++++++++++++++--- scripts/sync_protobuf/_utils.py | 2 +- scripts/sync_protobuf/google_protobuf.py | 4 ++-- scripts/sync_protobuf/s2clientprotocol.py | 2 +- scripts/sync_protobuf/tensorflow.py | 5 +++-- .../s2clientprotocol/raw_pb2.pyi | 12 +++-------- .../s2clientprotocol/sc2api_pb2.pyi | 12 +++-------- .../s2clientprotocol/spatial_pb2.pyi | 12 +++-------- .../s2clientprotocol/ui_pb2.pyi | 8 ++------ .../xla/tsl/protobuf/test_log_pb2.pyi | 3 ++- .../example_parser_configuration_pb2.pyi | 3 ++- .../core/framework/tensor_shape_pb2.pyi | 3 ++- .../core/framework/tensor_slice_pb2.pyi | 3 ++- .../tensorflow/core/protobuf/cluster_pb2.pyi | 1 - .../core/protobuf/device_filters_pb2.pyi | 1 - .../tensorflow/core/util/test_log_pb2.pyi | 3 ++- .../keras/protobuf/saved_metadata_pb2.pyi | 3 ++- .../tensorflow/tsl/protobuf/dnn_pb2.pyi | 3 ++- .../tsl/protobuf/error_codes_pb2.pyi | 1 - tests/mypy_test.py | 5 ++--- tests/pytype_test.py | 4 ++-- tests/regr_test.py | 3 +-- tests/stubtest_stdlib.py | 2 +- tests/stubtest_third_party.py | 2 +- 26 files changed, 60 insertions(+), 65 deletions(-) diff --git a/lib/ts_utils/metadata.py b/lib/ts_utils/metadata.py index 2942794e91ee..793b3b7a6d1e 100644 --- a/lib/ts_utils/metadata.py +++ b/lib/ts_utils/metadata.py @@ -184,7 +184,7 @@ def is_obsolete(self) -> bool: class NoSuchStubError(ValueError): - """Raise NoSuchStubError to indicate that a stubs/{distribution} directory doesn't exist""" + """Raise NoSuchStubError to indicate that a stubs/{distribution} directory doesn't exist.""" @cache @@ -302,9 +302,10 @@ def read_metadata(distribution: str) -> StubMetadata: def update_metadata(distribution: str, **new_values: object) -> tomlkit.TOMLDocument: - """Updates a distribution's METADATA.toml. + """Update a distribution's METADATA.toml. - Return the updated TOML dictionary for use without having to open the file separately.""" + Return the updated TOML dictionary for use without having to open the file separately. + """ path = metadata_path(distribution) try: with path.open("rb") as file: diff --git a/lib/ts_utils/utils.py b/lib/ts_utils/utils.py index 4dfe05488275..4cee6797837e 100644 --- a/lib/ts_utils/utils.py +++ b/lib/ts_utils/utils.py @@ -92,7 +92,6 @@ def venv_python(venv_dir: Path) -> Path: @cache def parse_requirements() -> Mapping[str, Requirement]: """Return a dictionary of requirements from the requirements file.""" - with REQUIREMENTS_PATH.open(encoding="UTF-8") as requirements_file: stripped_lines = map(strip_comments, requirements_file) stripped_more = [li for li in stripped_lines if not li.startswith("-")] diff --git a/pyproject.toml b/pyproject.toml index 424fb108d175..1909a06169e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ exclude = ["**/test_cases/**/*.py"] external = ["F821", "NQA", "Y"] select = [ "B", # flake8-bugbear + "D", # pydocstyle "FA", # flake8-future-annotations "I", # isort "PGH", # pygrep-hooks @@ -74,6 +75,7 @@ select = [ "PYI064", # `Final[Literal[{literal}]]` can be replaced with a bare Final ] extend-safe-fixes = [ + "D200", # One-line docstring should fit on one line "UP036", # Remove unnecessary `sys.version_info` blocks ] ignore = [ @@ -88,11 +90,15 @@ 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)` + # We're not a library, no need to document everything + "D1", # Missing docstring in ... + # Doesn't support split "summary line" + "D205", # 1 blank line required between summary line and description # 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()` + # 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 ### @@ -116,11 +122,19 @@ ignore = [ # Issues with using a star-imported name will be caught by type-checkers. "F405", # may be undefined, or defined from star imports ] -# See comment on black's force-exclude config above "*_pb2.pyi" = [ + # Non-autofixable docstring lints on autogenerated modules + "D210", # No whitespaces allowed surrounding docstring text + # These modify the docstring content other than spaces + "D301", # Use r""" if any backslashes in a docstring + "D40", + # See comment on black's force-exclude config above "E501", # Line too long ] +[tool.ruff.lint.pydocstyle] +convention = "pep257" # https://docs.astral.sh/ruff/settings/#lint_pydocstyle_convention + [tool.ruff.lint.isort] split-on-trailing-comma = false combine-as-imports = true diff --git a/scripts/sync_protobuf/_utils.py b/scripts/sync_protobuf/_utils.py index b27b566ad3d8..0c49c5a6fa9a 100644 --- a/scripts/sync_protobuf/_utils.py +++ b/scripts/sync_protobuf/_utils.py @@ -33,7 +33,7 @@ def extract_archive(archive_path: StrPath, destination: StrPath) -> None: def run_protoc( proto_paths: Iterable[StrPath], mypy_out: StrPath, proto_globs: Iterable[str], cwd: StrOrBytesPath | None = None ) -> str: - """TODO: Describe parameters and return""" + """TODO: Describe parameters and return.""" protoc_version = ( subprocess.run([sys.executable, "-m", "grpc_tools.protoc", "--version"], capture_output=True).stdout.decode().strip() ) diff --git a/scripts/sync_protobuf/google_protobuf.py b/scripts/sync_protobuf/google_protobuf.py index da2ced6f9fc7..7fabbe5bbc4b 100644 --- a/scripts/sync_protobuf/google_protobuf.py +++ b/scripts/sync_protobuf/google_protobuf.py @@ -31,7 +31,7 @@ def extract_python_version(file_path: Path) -> str: - """Extract the Python version from https://github.com/protocolbuffers/protobuf/blob/main/version.json""" + """Extract the Python version from https://github.com/protocolbuffers/protobuf/blob/main/version.json .""" with open(file_path) as file: data: dict[str, Any] = json.load(file) # The root key will be the protobuf source code version @@ -44,7 +44,7 @@ def extract_proto_file_paths(temp_dir: Path) -> list[str]: """ Roughly reproduce the subset of .proto files on the public interface as described in py_proto_library calls in - https://github.com/protocolbuffers/protobuf/blob/main/python/dist/BUILD.bazel + https://github.com/protocolbuffers/protobuf/blob/main/python/dist/BUILD.bazel . """ 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)) diff --git a/scripts/sync_protobuf/s2clientprotocol.py b/scripts/sync_protobuf/s2clientprotocol.py index 8f86fe5dccdd..0f7997fff0a0 100644 --- a/scripts/sync_protobuf/s2clientprotocol.py +++ b/scripts/sync_protobuf/s2clientprotocol.py @@ -29,7 +29,7 @@ def extract_python_version(file_path: Path) -> str: - """Extract Python version from s2clientprotocol's build file""" + """Extract Python version from s2clientprotocol's build file.""" match = re.search(VERSION_PATTERN, file_path.read_text()) assert match return match.group(1) diff --git a/scripts/sync_protobuf/tensorflow.py b/scripts/sync_protobuf/tensorflow.py index 8328ca2c0e09..0460fc1093dc 100644 --- a/scripts/sync_protobuf/tensorflow.py +++ b/scripts/sync_protobuf/tensorflow.py @@ -56,14 +56,15 @@ def move_tree(source: Path, destination: Path) -> None: """Move directory and merge if destination already exists. - Can't use shutil.move because it can't merge existing directories.""" + Can't use shutil.move because it can't merge existing directories. + """ print(f"Moving '{source}' to '{destination}'") shutil.copytree(source, destination, dirs_exist_ok=True) shutil.rmtree(source) def post_creation() -> None: - """Move third-party and fix imports""" + """Move third-party and fix imports.""" print() move_tree(STUBS_FOLDER / "tsl", STUBS_FOLDER / "tensorflow" / "tsl") move_tree(STUBS_FOLDER / "xla", STUBS_FOLDER / "tensorflow" / "compiler" / "xla") diff --git a/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi index 35a08c2337ea..1a6ad91860b8 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi @@ -92,9 +92,7 @@ global___CloakState = CloakState @typing.final class StartRaw(google.protobuf.message.Message): - """ - Start - """ + """Start""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -145,9 +143,7 @@ global___StartRaw = StartRaw @typing.final class ObservationRaw(google.protobuf.message.Message): - """ - Observation - """ + """Observation""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -580,9 +576,7 @@ global___Effect = Effect @typing.final class ActionRaw(google.protobuf.message.Message): - """ - Action - """ + """Action""" DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi index b979697237f5..68c926c62435 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi @@ -86,9 +86,7 @@ class _DifficultyEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._Enu CheatInsane: _Difficulty.ValueType # 10 class Difficulty(_Difficulty, metaclass=_DifficultyEnumTypeWrapper): - """ - Game Setup - """ + """Game Setup""" VeryEasy: Difficulty.ValueType # 1 Easy: Difficulty.ValueType # 2 @@ -218,9 +216,7 @@ global___Result = Result @typing.final class Request(google.protobuf.message.Message): - """ - Request/Response - """ + """Request/Response""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -1784,9 +1780,7 @@ global___PlayerInfo = PlayerInfo @typing.final class PlayerCommon(google.protobuf.message.Message): - """ - During Game - """ + """During Game""" DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi index f2e686f08242..154e98f1dac1 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi @@ -23,9 +23,7 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing.final class ObservationFeatureLayer(google.protobuf.message.Message): - """ - Observation - Feature Layer - """ + """Observation - Feature Layer""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -304,9 +302,7 @@ global___FeatureLayersMinimap = FeatureLayersMinimap @typing.final class ObservationRender(google.protobuf.message.Message): - """ - Observation - Rendered - """ + """Observation - Rendered""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -329,9 +325,7 @@ global___ObservationRender = ObservationRender @typing.final class ActionSpatial(google.protobuf.message.Message): - """ - Action - """ + """Action""" DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi index 65a0e165a43d..56dabd5190b9 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi @@ -22,9 +22,7 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing.final class ObservationUI(google.protobuf.message.Message): - """ - Observation - """ + """Observation""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -250,9 +248,7 @@ global___ProductionPanel = ProductionPanel @typing.final class ActionUI(google.protobuf.message.Message): - """ - Action - """ + """Action""" DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi b/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi index 0e06ea85faa7..d4e6208e05af 100644 --- a/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi +++ b/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the results of benchmarks and unit tests.""" +Protocol messages for describing the results of benchmarks and unit tests. +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi b/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi index 6b5c255da3b4..45c4f97a66aa 100644 --- a/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the configuration of the ExampleParserOp.""" +Protocol messages for describing the configuration of the ExampleParserOp. +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi b/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi index 2d852a920271..2e34b7c8544d 100644 --- a/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol buffer representing the shape of tensors.""" +Protocol buffer representing the shape of tensors. +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi b/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi index 949fd0f1d6a3..2942bf6a13e1 100644 --- a/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol buffer representing slices of a tensor""" +Protocol buffer representing slices of a tensor +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi b/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi index ae19698d703d..dc0c5647740f 100644 --- a/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi @@ -34,7 +34,6 @@ class JobDef(google.protobuf.message.Message): EXAMPLES -------- - 1. A single-process cluster, containing "/job:local/task:0". Cluster: diff --git a/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi b/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi index f4e0c8efe920..dfb05c65a5bd 100644 --- a/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi @@ -40,7 +40,6 @@ class TaskDeviceFilters(google.protobuf.message.Message): EXAMPLES -------- - A two-job cluster with the following ClusterDef: Cluster: diff --git a/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi b/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi index 88bdc15d87ec..ba382a6ab874 100644 --- a/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the results of benchmarks and unit tests.""" +Protocol messages for describing the results of benchmarks and unit tests. +""" import google.protobuf.descriptor from tensorflow.compiler.xla.tsl.protobuf.test_log_pb2 import ( diff --git a/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi b/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi index 0133517d273f..e79334ec8e82 100644 --- a/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi +++ b/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protobuf containing the metadata for each Keras object saved in a SavedModel.""" +Protobuf containing the metadata for each Keras object saved in a SavedModel. +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi b/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi index 929709311d04..3718f2d0a485 100644 --- a/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi +++ b/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi @@ -1,7 +1,8 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -LINT: LEGACY_NAMES""" +LINT: LEGACY_NAMES +""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi b/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi index 3b0b8dcf4b37..61f82bdec57c 100644 --- a/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi +++ b/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi @@ -152,7 +152,6 @@ class Code(_Code, metaclass=_CodeEnumTypeWrapper): """The canonical error codes for TensorFlow APIs. Warnings: - - Do not change any numeric assignments. - Changes to this list should only be made if there is a compelling need that can't be satisfied in another way. Such changes diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b1ad54735be9..b3c18769b14b 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -62,7 +62,7 @@ class CommandLineArgs: def valid_path(cmd_arg: str) -> Path: - """Helper function for argument-parsing""" + """Helper function for argument-parsing.""" # noqa: D401 path = Path(cmd_arg) if not path.exists(): raise argparse.ArgumentTypeError(f'"{path}" does not exist in typeshed!') @@ -72,7 +72,7 @@ def valid_path(cmd_arg: str) -> Path: def remove_dev_suffix(version: str) -> str: - """Helper function for argument-parsing""" + """Helper function for argument-parsing.""" # noqa: D401 if version.endswith("-dev"): return version[: -len("-dev")] return version @@ -303,7 +303,6 @@ def test_third_party_distribution( Return a tuple, where the first element indicates mypy's return code and the second element is the number of checked files. """ - files: list[Path] = [] configurations: list[MypyDistConf] = [] seen_dists: set[str] = set() diff --git a/tests/pytype_test.py b/tests/pytype_test.py index 366d279f2844..ea1a12c202b9 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -74,7 +74,7 @@ def create_parser() -> argparse.ArgumentParser: def run_pytype(*, filename: str, python_version: str, missing_modules: Iterable[str]) -> str | None: - """Runs pytype, returning the stderr if any.""" + """Run pytype, returning the stderr if any.""" if python_version not in _LOADERS: options = pytype_config.Options.create("", parse_pyi=True, python_version=python_version) # For simplicity, pretends missing modules are part of the stdlib. @@ -107,7 +107,7 @@ def _get_relative(filename: str) -> str: def _get_module_name(filename: str) -> str: - """Converts a filename {subdir}/m.n/module/foo to module.foo.""" + """Convert a filename {subdir}/m.n/module/foo to module.foo.""" parts = _get_relative(filename).split(os.path.sep) if parts[0] == "stdlib": module_parts = parts[1:] diff --git a/tests/regr_test.py b/tests/regr_test.py index 0889b3fb6bfc..033bfe8e4ebd 100755 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -44,8 +44,7 @@ def distribution_with_test_cases(distribution_name: str) -> DistributionTests: - """Helper function for argument-parsing.""" - + """Helper function for argument-parsing.""" # noqa: D401 try: return distribution_info(distribution_name) except RuntimeError as exc: diff --git a/tests/stubtest_stdlib.py b/tests/stubtest_stdlib.py index 5134f8270db8..a2d2afa90ba2 100755 --- a/tests/stubtest_stdlib.py +++ b/tests/stubtest_stdlib.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Test typeshed's stdlib using stubtest +"""Test typeshed's stdlib using stubtest. stubtest is a script in the mypy project that compares stubs to the actual objects at runtime. Note that therefore the output of stubtest depends on which Python version it is run with. diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index e10fbf96c8f8..82ea6ca52c84 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Test typeshed's third party stubs using stubtest""" +"""Test typeshed's third party stubs using stubtest.""" from __future__ import annotations From fc8dd046a3728210bd8e744e8a7249d9ca547fe8 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 13:54:54 -0500 Subject: [PATCH 2/6] Revert changes on *_pb2.pyi --- pyproject.toml | 7 ++----- stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi | 12 +++++++++--- .../s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi | 12 +++++++++--- .../s2clientprotocol/spatial_pb2.pyi | 12 +++++++++--- stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi | 8 ++++++-- .../compiler/xla/tsl/protobuf/test_log_pb2.pyi | 3 +-- .../example/example_parser_configuration_pb2.pyi | 3 +-- .../tensorflow/core/framework/tensor_shape_pb2.pyi | 3 +-- .../tensorflow/core/framework/tensor_slice_pb2.pyi | 3 +-- .../tensorflow/core/protobuf/cluster_pb2.pyi | 1 + .../tensorflow/core/protobuf/device_filters_pb2.pyi | 1 + .../tensorflow/tensorflow/core/util/test_log_pb2.pyi | 3 +-- .../python/keras/protobuf/saved_metadata_pb2.pyi | 3 +-- stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi | 3 +-- .../tensorflow/tsl/protobuf/error_codes_pb2.pyi | 1 + 15 files changed, 45 insertions(+), 30 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e0a65fbdaac5..36f8f6e32933 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,11 +141,8 @@ ignore = [ "RUF023", ] "*_pb2.pyi" = [ - # Non-autofixable docstring lints on autogenerated modules - "D210", # No whitespaces allowed surrounding docstring text - # These modify the docstring content other than spaces - "D301", # Use r""" if any backslashes in a docstring - "D40", + # Leave the docstrings as-is, matchin source + "D", # pydocstyle # See comment on black's force-exclude config above "E501", # Line too long ] diff --git a/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi index 1a6ad91860b8..35a08c2337ea 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/raw_pb2.pyi @@ -92,7 +92,9 @@ global___CloakState = CloakState @typing.final class StartRaw(google.protobuf.message.Message): - """Start""" + """ + Start + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -143,7 +145,9 @@ global___StartRaw = StartRaw @typing.final class ObservationRaw(google.protobuf.message.Message): - """Observation""" + """ + Observation + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -576,7 +580,9 @@ global___Effect = Effect @typing.final class ActionRaw(google.protobuf.message.Message): - """Action""" + """ + Action + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi index 68c926c62435..b979697237f5 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/sc2api_pb2.pyi @@ -86,7 +86,9 @@ class _DifficultyEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._Enu CheatInsane: _Difficulty.ValueType # 10 class Difficulty(_Difficulty, metaclass=_DifficultyEnumTypeWrapper): - """Game Setup""" + """ + Game Setup + """ VeryEasy: Difficulty.ValueType # 1 Easy: Difficulty.ValueType # 2 @@ -216,7 +218,9 @@ global___Result = Result @typing.final class Request(google.protobuf.message.Message): - """Request/Response""" + """ + Request/Response + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -1780,7 +1784,9 @@ global___PlayerInfo = PlayerInfo @typing.final class PlayerCommon(google.protobuf.message.Message): - """During Game""" + """ + During Game + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi index 154e98f1dac1..f2e686f08242 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/spatial_pb2.pyi @@ -23,7 +23,9 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing.final class ObservationFeatureLayer(google.protobuf.message.Message): - """Observation - Feature Layer""" + """ + Observation - Feature Layer + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -302,7 +304,9 @@ global___FeatureLayersMinimap = FeatureLayersMinimap @typing.final class ObservationRender(google.protobuf.message.Message): - """Observation - Rendered""" + """ + Observation - Rendered + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -325,7 +329,9 @@ global___ObservationRender = ObservationRender @typing.final class ActionSpatial(google.protobuf.message.Message): - """Action""" + """ + Action + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi index 56dabd5190b9..65a0e165a43d 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/ui_pb2.pyi @@ -22,7 +22,9 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing.final class ObservationUI(google.protobuf.message.Message): - """Observation""" + """ + Observation + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -248,7 +250,9 @@ global___ProductionPanel = ProductionPanel @typing.final class ActionUI(google.protobuf.message.Message): - """Action""" + """ + Action + """ DESCRIPTOR: google.protobuf.descriptor.Descriptor diff --git a/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi b/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi index d4e6208e05af..0e06ea85faa7 100644 --- a/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi +++ b/stubs/tensorflow/tensorflow/compiler/xla/tsl/protobuf/test_log_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the results of benchmarks and unit tests. -""" +Protocol messages for describing the results of benchmarks and unit tests.""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi b/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi index 45c4f97a66aa..6b5c255da3b4 100644 --- a/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/example/example_parser_configuration_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the configuration of the ExampleParserOp. -""" +Protocol messages for describing the configuration of the ExampleParserOp.""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi b/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi index 2e34b7c8544d..2d852a920271 100644 --- a/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/framework/tensor_shape_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol buffer representing the shape of tensors. -""" +Protocol buffer representing the shape of tensors.""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi b/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi index 2942bf6a13e1..949fd0f1d6a3 100644 --- a/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/framework/tensor_slice_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol buffer representing slices of a tensor -""" +Protocol buffer representing slices of a tensor""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi b/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi index dc0c5647740f..ae19698d703d 100644 --- a/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/protobuf/cluster_pb2.pyi @@ -34,6 +34,7 @@ class JobDef(google.protobuf.message.Message): EXAMPLES -------- + 1. A single-process cluster, containing "/job:local/task:0". Cluster: diff --git a/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi b/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi index dfb05c65a5bd..f4e0c8efe920 100644 --- a/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/protobuf/device_filters_pb2.pyi @@ -40,6 +40,7 @@ class TaskDeviceFilters(google.protobuf.message.Message): EXAMPLES -------- + A two-job cluster with the following ClusterDef: Cluster: diff --git a/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi b/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi index ba382a6ab874..88bdc15d87ec 100644 --- a/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi +++ b/stubs/tensorflow/tensorflow/core/util/test_log_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protocol messages for describing the results of benchmarks and unit tests. -""" +Protocol messages for describing the results of benchmarks and unit tests.""" import google.protobuf.descriptor from tensorflow.compiler.xla.tsl.protobuf.test_log_pb2 import ( diff --git a/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi b/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi index e79334ec8e82..0133517d273f 100644 --- a/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi +++ b/stubs/tensorflow/tensorflow/python/keras/protobuf/saved_metadata_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -Protobuf containing the metadata for each Keras object saved in a SavedModel. -""" +Protobuf containing the metadata for each Keras object saved in a SavedModel.""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi b/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi index 3718f2d0a485..929709311d04 100644 --- a/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi +++ b/stubs/tensorflow/tensorflow/tsl/protobuf/dnn_pb2.pyi @@ -1,8 +1,7 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file -LINT: LEGACY_NAMES -""" +LINT: LEGACY_NAMES""" import builtins import collections.abc diff --git a/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi b/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi index 61f82bdec57c..3b0b8dcf4b37 100644 --- a/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi +++ b/stubs/tensorflow/tensorflow/tsl/protobuf/error_codes_pb2.pyi @@ -152,6 +152,7 @@ class Code(_Code, metaclass=_CodeEnumTypeWrapper): """The canonical error codes for TensorFlow APIs. Warnings: + - Do not change any numeric assignments. - Changes to this list should only be made if there is a compelling need that can't be satisfied in another way. Such changes From 1e920d4b9c0a3dfe9d623e7c45873d08861b4cd6 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 13:59:26 -0500 Subject: [PATCH 3/6] No need for D200 in extend-safe-fixes if not applying on autogenerated files --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 36f8f6e32933..333794abbca8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,6 @@ select = [ "PYI064", # `Final[Literal[{literal}]]` can be replaced with a bare Final ] extend-safe-fixes = [ - "D200", # One-line docstring should fit on one line "UP036", # Remove unnecessary `sys.version_info` blocks ] ignore = [ From 0c55b40b92778b2fdb07ea28bf8931a7e6a5c84b Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 16:54:30 -0500 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Alex Waygood --- pyproject.toml | 2 +- tests/mypy_test.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 333794abbca8..a5eb4070b9b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -140,7 +140,7 @@ ignore = [ "RUF023", ] "*_pb2.pyi" = [ - # Leave the docstrings as-is, matchin source + # Leave the docstrings as-is, matching source "D", # pydocstyle # See comment on black's force-exclude config above "E501", # Line too long diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b3c18769b14b..b74df91dbd99 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -62,7 +62,7 @@ class CommandLineArgs: def valid_path(cmd_arg: str) -> Path: - """Helper function for argument-parsing.""" # noqa: D401 + """Parse a CLI argument that is intended to point to a valid typeshed path.""" path = Path(cmd_arg) if not path.exists(): raise argparse.ArgumentTypeError(f'"{path}" does not exist in typeshed!') @@ -72,7 +72,10 @@ def valid_path(cmd_arg: str) -> Path: def remove_dev_suffix(version: str) -> str: - """Helper function for argument-parsing.""" # noqa: D401 + """Remove the `-dev` suffix from a version string. + + This is a helper function for argument-parsing. + """ if version.endswith("-dev"): return version[: -len("-dev")] return version From 59dc621a7c2994a609f0698b5ee1f2b180d9f420 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 16:54:32 -0500 Subject: [PATCH 5/6] Last noqa: D401 --- tests/regr_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regr_test.py b/tests/regr_test.py index 72f1a6ceb901..573d25b72c99 100755 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -44,7 +44,7 @@ def distribution_with_test_cases(distribution_name: str) -> DistributionTests: - """Helper function for argument-parsing.""" # noqa: D401 + """Parse a CLI argument that is intended to be to a valid typeshed distribution.""" try: return distribution_info(distribution_name) except RuntimeError as exc: From 7ddfa586b49d640b75053fbef24a01ca3fa47126 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:56:13 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- tests/mypy_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b74df91dbd99..67762bba93d6 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -73,7 +73,7 @@ def valid_path(cmd_arg: str) -> Path: def remove_dev_suffix(version: str) -> str: """Remove the `-dev` suffix from a version string. - + This is a helper function for argument-parsing. """ if version.endswith("-dev"):