From d348befd4daf1d75267c7ee2b45df94e1a7e46c5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 20:28:18 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/codespell-project/codespell: v2.3.0 → v2.4.1](https://github.com/codespell-project/codespell/compare/v2.3.0...v2.4.1) - [github.com/PyCQA/docformatter: 06907d0267368b49b9180eed423fae5697c1e909 → v1.7.5](https://github.com/PyCQA/docformatter/compare/06907d0267368b49b9180eed423fae5697c1e909...v1.7.5) - [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.11.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.6...v0.11.4) - [github.com/executablebooks/mdformat: 0.7.21 → 0.7.22](https://github.com/executablebooks/mdformat/compare/0.7.21...0.7.22) - [github.com/pre-commit/mirrors-prettier: v3.1.0 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v3.1.0...v4.0.0-alpha.8) --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2e475f602913..b0d60832317a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,14 +51,14 @@ repos: - id: detect-private-key - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell additional_dependencies: [tomli] #args: ["--write-changes"] # uncomment if you want to get automatic fixing - repo: https://github.com/PyCQA/docformatter - rev: 06907d0267368b49b9180eed423fae5697c1e909 # todo: fix for docformatter after last 1.7.5 + rev: v1.7.5 # todo: fix for docformatter after last 1.7.5 hooks: - id: docformatter additional_dependencies: [tomli] @@ -70,7 +70,7 @@ repos: - id: sphinx-lint - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.11.4 hooks: # try to fix what is possible - id: ruff @@ -81,7 +81,7 @@ repos: - id: ruff - repo: https://github.com/executablebooks/mdformat - rev: 0.7.21 + rev: 0.7.22 hooks: - id: mdformat additional_dependencies: @@ -96,7 +96,7 @@ repos: )$ - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 + rev: v4.0.0-alpha.8 hooks: - id: prettier # https://prettier.io/docs/en/options.html#print-width From 4014c4a9298c56c4024498463a4305d695823d9b Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Tue, 8 Apr 2025 12:05:54 +0200 Subject: [PATCH 2/3] Apply suggestions from code review --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b0d60832317a3..4723638fc5e4a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,7 +58,7 @@ repos: #args: ["--write-changes"] # uncomment if you want to get automatic fixing - repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 # todo: fix for docformatter after last 1.7.5 + rev: 06907d0267368b49b9180eed423fae5697c1e909 # todo: fix for docformatter after last 1.7.5 hooks: - id: docformatter additional_dependencies: [tomli] @@ -96,7 +96,7 @@ repos: )$ - repo: https://github.com/pre-commit/mirrors-prettier - rev: v4.0.0-alpha.8 + rev: v3.1.0 hooks: - id: prettier # https://prettier.io/docs/en/options.html#print-width From d47fc12ea7c12096f0416df1273479ed3682f857 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 10:06:12 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning/pytorch/callbacks/timer.py | 4 ++-- tests/tests_pytorch/helpers/datasets.py | 2 +- tests/tests_pytorch/trainer/connectors/test_data_connector.py | 2 +- tests/tests_pytorch/trainer/logging_/test_logger_connector.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lightning/pytorch/callbacks/timer.py b/src/lightning/pytorch/callbacks/timer.py index b6b74d280427c..91f5fd0e75d9b 100644 --- a/src/lightning/pytorch/callbacks/timer.py +++ b/src/lightning/pytorch/callbacks/timer.py @@ -111,8 +111,8 @@ def __init__( self._duration = duration.total_seconds() if duration is not None else None self._interval = interval self._verbose = verbose - self._start_time: dict[RunningStage, Optional[float]] = {stage: None for stage in RunningStage} - self._end_time: dict[RunningStage, Optional[float]] = {stage: None for stage in RunningStage} + self._start_time: dict[RunningStage, Optional[float]] = dict.fromkeys(RunningStage) + self._end_time: dict[RunningStage, Optional[float]] = dict.fromkeys(RunningStage) self._offset = 0 def start_time(self, stage: str = RunningStage.TRAINING) -> Optional[float]: diff --git a/tests/tests_pytorch/helpers/datasets.py b/tests/tests_pytorch/helpers/datasets.py index 014fb374e5d5e..638d3a2946a74 100644 --- a/tests/tests_pytorch/helpers/datasets.py +++ b/tests/tests_pytorch/helpers/datasets.py @@ -148,7 +148,7 @@ def __init__(self, root: str, num_samples: int = 100, digits: Optional[Sequence] @staticmethod def _prepare_subset(full_data: Tensor, full_targets: Tensor, num_samples: int, digits: Sequence): - classes = {d: 0 for d in digits} + classes = dict.fromkeys(digits, 0) indexes = [] for idx, target in enumerate(full_targets): label = target.item() diff --git a/tests/tests_pytorch/trainer/connectors/test_data_connector.py b/tests/tests_pytorch/trainer/connectors/test_data_connector.py index ceb0418f2cb1d..1bb0d1478e7d3 100644 --- a/tests/tests_pytorch/trainer/connectors/test_data_connector.py +++ b/tests/tests_pytorch/trainer/connectors/test_data_connector.py @@ -497,7 +497,7 @@ def test_dataloader_source_request_from_module(): @pytest.mark.parametrize( - "hook_name", ("on_before_batch_transfer", "transfer_batch_to_device", "on_after_batch_transfer") + "hook_name", ["on_before_batch_transfer", "transfer_batch_to_device", "on_after_batch_transfer"] ) class TestDataHookSelector: def overridden_func(self, batch, *args, **kwargs): diff --git a/tests/tests_pytorch/trainer/logging_/test_logger_connector.py b/tests/tests_pytorch/trainer/logging_/test_logger_connector.py index faf88a09f6499..d3d355edb003b 100644 --- a/tests/tests_pytorch/trainer/logging_/test_logger_connector.py +++ b/tests/tests_pytorch/trainer/logging_/test_logger_connector.py @@ -246,7 +246,7 @@ def test_fx_validator_integration(tmp_path): }) trainer.test(model, verbose=False) - not_supported.update({k: "result collection is not registered yet" for k in not_supported}) + not_supported.update(dict.fromkeys(not_supported, "result collection is not registered yet")) not_supported.update({ "predict_dataloader": "result collection is not registered yet", "on_predict_model_eval": "result collection is not registered yet",