From 198f0eded86604c66a39c4d1d5e20b13de48e223 Mon Sep 17 00:00:00 2001 From: Hongbo Miao <3375461+hongbo-miao@users.noreply.github.com> Date: Wed, 8 Jan 2025 02:30:37 -0800 Subject: [PATCH] feat(ruff): enable flake8-annotations, flake8-2020, pycodestyle (#22404) --- .ruff.toml | 8 ++- README.md | 2 + aerospace/hm-aerosandbox/src/dummy_test.py | 2 +- aerospace/hm-openaerostruct/src/dummy_test.py | 2 +- api-python/routers/health_test.py | 2 +- api-python/routers/motor.py | 2 +- api-python/routers/motor_test.py | 2 +- api-python/utils/kafka_util.py | 2 +- api-rust/scripts/download_model.py | 4 +- .../opal_fetcher_postgres/provider.py | 26 +++++++--- .../applications/calculate/src/dummy_test.py | 2 +- .../process-flight-data/src/dummy_test.py | 2 +- cloud-computing/hm-skypilot/dummy_test.py | 2 +- cloud-infrastructure/hm-pulumi/dummy_test.py | 2 +- .../aws-glue/spark-scripts/src/dummy_test.py | 2 +- .../pytorch-mnist/src/dummy_test.py | 2 +- .../pytorch-mnist/src/main.py | 2 +- .../pytorch-mnist/src/models/net.py | 6 +-- .../src/utils/average_gradients.py | 3 +- .../pytorch-mnist/src/utils/get_args.py | 2 +- .../src/utils/get_test_data_loader.py | 10 ++-- .../src/utils/get_train_data_loader.py | 21 +++++--- .../pytorch-mnist/src/utils/save_model.py | 8 +-- .../pytorch-mnist/src/utils/test.py | 8 +-- .../pytorch-mnist/src/utils/train.py | 6 ++- .../pcluster/dummy_test.py | 2 +- cloud-security/hm-prowler/dummy_test.py | 2 +- .../hm-imagebind/src/dummy_test.py | 2 +- computer-vision/hm-imagebind/src/main.py | 8 +-- computer-vision/hm-open3d/src/dummy_test.py | 2 +- computer-vision/hm-open3d/src/main.py | 2 +- .../mount-saint-helens/src/dummy_test.py | 2 +- .../detect-objects/src/dummy_test.py | 2 +- computer-vision/open-clip/src/dummy_test.py | 2 +- computer-vision/open-clip/src/main.py | 2 +- data-analytics/hm-cudf/src/dummy_test.py | 2 +- data-analytics/hm-cupy/src/dummy_test.py | 2 +- data-analytics/hm-geopandas/src/dummy_test.py | 2 +- data-analytics/hm-networkx/src/dummy_test.py | 2 +- data-analytics/hm-numba/src/dummy_test.py | 2 +- data-analytics/hm-pandas/src/dummy_test.py | 2 +- data-analytics/hm-polars/src/dummy_test.py | 2 +- data-distribution-service/dummy_test.py | 2 +- data-distribution-service/publish.py | 2 +- data-distribution-service/subscribe.py | 4 +- data-orchestration/hm-airflow/dags/greet.py | 16 ++++-- data-orchestration/hm-airflow/dummy_test.py | 2 +- .../workflows/calculate/src/dummy_test.py | 2 +- .../workflows/greet/src/dummy_test.py | 2 +- .../print-platform/src/dummy_test.py | 2 +- .../workflows/print-platform/src/main.py | 2 +- .../src/dummy_test.py | 2 +- .../src/dummy_test.py | 2 +- .../src/dummy_test.py | 2 +- .../src/utils/df_test.py | 2 +- .../src/utils/zone.py | 2 +- .../find-taxi-top-routes/src/dummy_test.py | 2 +- .../find-taxi-top-routes/src/utils/df_test.py | 2 +- .../find-taxi-top-routes/src/utils/zone.py | 2 +- .../recommend-movies/src/dummy_test.py | 2 +- .../applications/recommend-movies/src/main.py | 2 +- .../src/dummy_test.py | 2 +- .../src/main.py | 2 +- .../src/dummy_test.py | 2 +- .../read-delta-lake-by-trino/src/main.py | 2 +- .../write-to-delta-lake/src/dummy_test.py | 2 +- .../write-to-delta-lake/src/main.py | 2 +- .../hm-duckdb/query-duckdb/src/dummy_test.py | 2 +- .../hm-duckdb/query-lance/src/dummy_test.py | 2 +- .../hm-duckdb/query-parquet/src/dummy_test.py | 2 +- .../query-protobuf/src/dummy_test.py | 2 +- data-storage/hm-lancedb/src/dummy_test.py | 2 +- data-storage/hm-lancedb/src/main.py | 2 +- data-storage/hm-protobuf/src/dummy_test.py | 2 +- data-storage/lance/src/dummy_test.py | 2 +- .../projects/dbt_hm_postgres/dummy_test.py | 2 +- .../grafana/hm-dashboard/src/dummy_test.py | 2 +- .../iads-config-reader/src/dummy_test.py | 2 +- .../iads-config-reader/src/main.py | 4 +- .../iads-data-reader/src/dummy_test.py | 2 +- .../iads-data-reader/src/main.py | 4 +- .../decode-can-data/src/dummy_test.py | 2 +- embedded-systems/decode-can-data/src/main.py | 4 +- .../format-can-data/src/dummy_test.py | 2 +- embedded-systems/hm-serial/src/dummy_test.py | 2 +- .../pack-unpack-data/src/dummy_test.py | 2 +- .../hm-pyvisa/src/dummy_test.py | 2 +- .../hm-tdms/src/dummy_test.py | 2 +- .../veristand/hm-veristand/src/dummy_test.py | 2 +- .../veristand/hm-veristand/src/main.py | 2 +- .../hm-jax/src/dummy_test.py | 2 +- hm-locust/src/dummy_test.py | 2 +- hm-locust/src/main.py | 8 +-- hm-xxhash/src/dummy_test.py | 2 +- .../convolutional-neural-network/src/args.py | 2 +- .../src/dummy_test.py | 2 +- .../src/evaluate.py | 4 +- .../convolutional-neural-network/src/main.py | 2 +- .../src/model/net.py | 4 +- .../convolutional-neural-network/src/train.py | 13 ++++- .../src/utils/writer.py | 4 +- machine-learning/dali/src/dummy_test.py | 2 +- machine-learning/dali/src/main.py | 3 +- machine-learning/feature-store/dummy_test.py | 2 +- .../graph-neural-network/src/args.py | 2 +- .../graph-neural-network/src/dummy_test.py | 2 +- .../graph-neural-network/src/main.py | 17 +++++-- .../graph-neural-network/src/model/conv.py | 50 ++++++++++--------- .../src/model/data_loader.py | 11 +++- .../graph-neural-network/src/model/gnn.py | 24 +++++---- .../hm-autogluon/src/dummy_test.py | 2 +- machine-learning/hm-docling/src/dummy_test.py | 2 +- .../hm-faster-whisper/src/dummy_test.py | 2 +- machine-learning/hm-flax/src/dummy_test.py | 2 +- machine-learning/hm-flax/src/main.py | 4 +- .../classify-image/src/dummy_test.py | 2 +- .../pipelines/calculate/src/dummy_test.py | 2 +- .../pipelines/calculate/src/main.py | 2 +- .../classify-mnist/src/dummy_test.py | 2 +- .../pipelines/classify-mnist/src/main.py | 14 +++--- .../applications/chat-pdf/src/dummy_test.py | 2 +- .../applications/chat-pdf/src/dummy_test.py | 2 +- .../applications/chat-pdf/src/dummy_test.py | 2 +- .../experiments/classify-mnist/src/args.py | 2 +- .../classify-mnist/src/dummy_test.py | 2 +- .../experiments/classify-mnist/src/main.py | 12 +++-- .../predict-diabetes/src/dummy_test.py | 2 +- .../experiments/predict-diabetes/src/main.py | 2 +- machine-learning/hm-rasa/actions/actions.py | 8 +-- machine-learning/hm-sglang/src/dummy_test.py | 2 +- .../live-line-chart/src/dummy_test.py | 2 +- .../applications/map/src/dummy_test.py | 2 +- .../analyze-sentiment/src/dummy_test.py | 2 +- machine-learning/mineru/src/dummy_test.py | 2 +- .../src/dummy_test.py | 2 +- .../cart-pole/src/dummy_test.py | 2 +- .../stable-diffusion/src/dummy_test.py | 2 +- machine-learning/stable-diffusion/src/main.py | 2 +- .../deploy/src/dummy_test.py | 2 +- .../infer/src/dummy_test.py | 2 +- .../src/dummy_test.py | 2 +- .../hm-triton/src/dummy_test.py | 2 +- parallel-computing/hm-triton/src/main.py | 8 +-- quantum-computing/src/dummy_test.py | 2 +- quantum-computing/src/main.py | 2 +- .../hm_python_package/hm_python_node.py | 6 +-- .../hm_python_package/test/test_copyright.py | 2 +- .../src/hm_python_package/test/test_flake8.py | 2 +- .../src/hm_python_package/test/test_pep257.py | 2 +- .../test/test_target_control_node.py | 31 +++++++----- .../turtle_robot/target_control_node.py | 8 +-- .../turtle_robot/turtle_robot_control_node.py | 20 ++++---- .../launch/turtle_robot.launch.py | 2 +- system-tools/ouch/Makefile | 2 +- 154 files changed, 357 insertions(+), 270 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 615c6e2914..36d0d75f0f 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -173,6 +173,7 @@ exclude = [ [lint] select = [ "AIR", # Airflow + "ANN", # flake8-annotations "ASYNC", # flake8-async "C90", # mccabe "COM", # flake8-commas @@ -197,9 +198,11 @@ select = [ "S", # flake8-bandit "TRY", # tryceratops "UP", # pyupgrade + "W", # pycodestyle + "YTT", # flake8-2020 ] ignore = [ - "S101", + "COM812", "D100", "D101", "D102", @@ -210,9 +213,10 @@ ignore = [ "D203", "D212", "E501", + "ISC001", "PLR0913", "PLR0915", "PLR2004", + "S101", "TRY003", - "COM812", ] diff --git a/README.md b/README.md index 3d70f57fa7..34a85dad50 100644 --- a/README.md +++ b/README.md @@ -737,6 +737,8 @@ The diagram illustrates the repository's architecture, which is considered overl - **End-to-end testing** - **Contract testing** - **Mutation testing** +- **Penetration testing** +- **Ethical testing** - **Performance testing** - **Permutation testing** - **Holdout testing** diff --git a/aerospace/hm-aerosandbox/src/dummy_test.py b/aerospace/hm-aerosandbox/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/aerospace/hm-aerosandbox/src/dummy_test.py +++ b/aerospace/hm-aerosandbox/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/aerospace/hm-openaerostruct/src/dummy_test.py b/aerospace/hm-openaerostruct/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/aerospace/hm-openaerostruct/src/dummy_test.py +++ b/aerospace/hm-openaerostruct/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/api-python/routers/health_test.py b/api-python/routers/health_test.py index 5acbd50fe2..3e120af7b8 100644 --- a/api-python/routers/health_test.py +++ b/api-python/routers/health_test.py @@ -4,7 +4,7 @@ client = TestClient(app) -def test_get_health(): +def test_get_health() -> None: response = client.get("/") assert response.status_code == 200 assert response.json() == {"api": "ok"} diff --git a/api-python/routers/motor.py b/api-python/routers/motor.py index 8e2aa62c6c..24977ce7f8 100644 --- a/api-python/routers/motor.py +++ b/api-python/routers/motor.py @@ -13,7 +13,7 @@ config = Config() -def get_producer(): +def get_producer() -> Producer: producer = Producer({"bootstrap.servers": config.KAFKA_BOOTSTRAP_SERVERS}) try: yield producer diff --git a/api-python/routers/motor_test.py b/api-python/routers/motor_test.py index b7c3027e35..d6a0ba0980 100644 --- a/api-python/routers/motor_test.py +++ b/api-python/routers/motor_test.py @@ -7,7 +7,7 @@ @patch("routers.motor.Producer") -def test_generate_motor_data(mock_producer): +def test_generate_motor_data(mock_producer: MagicMock) -> None: mock_producer_instance = MagicMock() mock_producer.return_value = mock_producer_instance diff --git a/api-python/utils/kafka_util.py b/api-python/utils/kafka_util.py index 3c3d9d2049..0532826475 100644 --- a/api-python/utils/kafka_util.py +++ b/api-python/utils/kafka_util.py @@ -2,7 +2,7 @@ from utils.logger import logger -def delivery_report(err: cimpl.KafkaError, msg: cimpl.Message): +def delivery_report(err: cimpl.KafkaError, msg: cimpl.Message) -> None: if err is not None: logger.error(f"Message delivery failed: {err}") else: diff --git a/api-rust/scripts/download_model.py b/api-rust/scripts/download_model.py index 6ae1ceeeb9..b01a4ae2d0 100644 --- a/api-rust/scripts/download_model.py +++ b/api-rust/scripts/download_model.py @@ -8,7 +8,7 @@ logger = logging.getLogger(__name__) -def download_labels(): +def download_labels() -> None: labels_url = ( "https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt" ) @@ -24,7 +24,7 @@ def download_labels(): logger.info("Labels file already exists") -def download_resnet18(): +def download_resnet18() -> None: model_path = Path("models/resnet18.ot") if not model_path.exists(): diff --git a/authorization/hm-opal-client/opal_fetcher_postgres/provider.py b/authorization/hm-opal-client/opal_fetcher_postgres/provider.py index 4f28f7c14f..eb104caacc 100644 --- a/authorization/hm-opal-client/opal_fetcher_postgres/provider.py +++ b/authorization/hm-opal-client/opal_fetcher_postgres/provider.py @@ -1,6 +1,7 @@ # https://github.com/permitio/opal-fetcher-postgres import json +from types import TracebackType from typing import Any, ClassVar import asyncpg @@ -59,7 +60,7 @@ def __init__(self, event: PostgresFetchEvent) -> None: def parse_event(self, event: FetchEvent) -> PostgresFetchEvent: return PostgresFetchEvent(**event.dict(exclude={"config"}), config=event.config) - async def __aenter__(self): + async def __aenter__(self) -> "PostgresFetchProvider": # self._event: PostgresFetchEvent # type casting dsn: str = self._event.url @@ -69,7 +70,7 @@ async def __aenter__(self): else self._event.config.connection_params.dict(exclude_none=True) ) - self._connection: asyncpg.Connection = await asyncpg.connect( + self._connection = await asyncpg.connect( dsn, **connection_params, ) @@ -81,31 +82,42 @@ async def __aenter__(self): schema="pg_catalog", ) - self._transaction: Transaction = self._connection.transaction(readonly=True) + self._transaction = self._connection.transaction(readonly=True) await self._transaction.__aenter__() return self - async def __aexit__(self, exc_type=None, exc_val=None, tb=None): + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + tb: TracebackType | None, + ) -> None: if self._transaction is not None: await self._transaction.__aexit__(exc_type, exc_val, tb) if self._connection is not None: await self._connection.close() - async def _fetch_(self): + async def _fetch_(self) -> list[asyncpg.Record]: if self._event.config is None: logger.warning("Incomplete fetcher config!") - return + return [] logger.debug(f"{self.__class__.__name__} fetching from {self._url}") if self._event.config.fetch_one: + if self._connection is None: + return [] row = await self._connection.fetchrow(self._event.config.query) return [row] else: + if self._connection is None: + return [] return await self._connection.fetch(self._event.config.query) - async def _process_(self, records: list[asyncpg.Record]): + async def _process_( + self, records: list[asyncpg.Record] + ) -> dict[str, asyncpg.Record] | list[asyncpg.Record]: if self._event.config is not None and self._event.config.fetch_one: if records and len(records) > 0: return dict(records[0]) diff --git a/cloud-computing/hm-ray/applications/calculate/src/dummy_test.py b/cloud-computing/hm-ray/applications/calculate/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-computing/hm-ray/applications/calculate/src/dummy_test.py +++ b/cloud-computing/hm-ray/applications/calculate/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-computing/hm-ray/applications/process-flight-data/src/dummy_test.py b/cloud-computing/hm-ray/applications/process-flight-data/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-computing/hm-ray/applications/process-flight-data/src/dummy_test.py +++ b/cloud-computing/hm-ray/applications/process-flight-data/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-computing/hm-skypilot/dummy_test.py b/cloud-computing/hm-skypilot/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-computing/hm-skypilot/dummy_test.py +++ b/cloud-computing/hm-skypilot/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-infrastructure/hm-pulumi/dummy_test.py b/cloud-infrastructure/hm-pulumi/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-infrastructure/hm-pulumi/dummy_test.py +++ b/cloud-infrastructure/hm-pulumi/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-infrastructure/terraform/environments/production/aws/general/files/aws-glue/spark-scripts/src/dummy_test.py b/cloud-infrastructure/terraform/environments/production/aws/general/files/aws-glue/spark-scripts/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-infrastructure/terraform/environments/production/aws/general/files/aws-glue/spark-scripts/src/dummy_test.py +++ b/cloud-infrastructure/terraform/environments/production/aws/general/files/aws-glue/spark-scripts/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/dummy_test.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/dummy_test.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/main.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/main.py index e544dead1f..751fa746b9 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/main.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/main.py @@ -8,7 +8,7 @@ from utils.train import train -def model_fn(model_dir): +def model_fn(model_dir: str) -> Net: if torch.cuda.is_available(): device = "cuda" elif torch.backends.mps.is_available(): diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/models/net.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/models/net.py index 5157af57ca..7b21f01955 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/models/net.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/models/net.py @@ -1,9 +1,9 @@ import torch.nn.functional as F # noqa: N812 # noqa: N812 -from torch import nn +from torch import Tensor, nn class Net(nn.Module): - def __init__(self): + def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) @@ -11,7 +11,7 @@ def __init__(self): self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) - def forward(self, x): + def forward(self, x: Tensor) -> Tensor: x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, 320) diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/average_gradients.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/average_gradients.py index 1162d951ae..e96537392c 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/average_gradients.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/average_gradients.py @@ -1,7 +1,8 @@ +import torch import torch.distributed as dist -def average_gradients(model): +def average_gradients(model: torch.nn.Module) -> None: # Gradient averaging. size = float(dist.get_world_size()) for param in model.parameters(): diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_args.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_args.py index 5789ed8da7..6ace807d05 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_args.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_args.py @@ -3,7 +3,7 @@ import os -def get_args(): +def get_args() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument( "--batch-size", diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_test_data_loader.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_test_data_loader.py index 7436a5b798..19beb248de 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_test_data_loader.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_test_data_loader.py @@ -1,14 +1,18 @@ import logging +from typing import Any import torch -import torch.utils.data -import torch.utils.data.distributed +from torch.utils.data import DataLoader from torchvision import datasets, transforms logger = logging.getLogger(__name__) -def get_test_data_loader(test_batch_size, training_dir, **kwargs): +def get_test_data_loader( + test_batch_size: int, + training_dir: str, + **kwargs: Any, # noqa: ANN401 +) -> DataLoader: logger.info("Get test data loader") return torch.utils.data.DataLoader( datasets.MNIST( diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_train_data_loader.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_train_data_loader.py index 5b16c2452c..f3d74082a3 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_train_data_loader.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/get_train_data_loader.py @@ -1,26 +1,31 @@ import logging +from typing import Any import torch -import torch.utils.data -import torch.utils.data.distributed +from torch.utils.data import DataLoader, Dataset +from torch.utils.data.distributed import DistributedSampler from torchvision import datasets, transforms logger = logging.getLogger(__name__) -def get_train_data_loader(batch_size, training_dir, is_distributed, **kwargs): +def get_train_data_loader( + batch_size: int, + training_dir: str, + is_distributed: bool, + **kwargs: Any, # noqa: ANN401 +) -> DataLoader: logger.info("Get train data loader") - dataset = datasets.MNIST( + dataset: Dataset = datasets.MNIST( training_dir, train=True, transform=transforms.Compose( [transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))], ), ) - train_sampler = ( - torch.utils.data.distributed.DistributedSampler(dataset) - if is_distributed - else None + + train_sampler: DistributedSampler | None = ( + DistributedSampler(dataset) if is_distributed else None ) return torch.utils.data.DataLoader( dataset, diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/save_model.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/save_model.py index a01a810757..0e959719ae 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/save_model.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/save_model.py @@ -1,14 +1,14 @@ import logging import os +from pathlib import Path import torch -import torch.utils.data -import torch.utils.data.distributed +from torch.nn import Module logger = logging.getLogger(__name__) -def save_model(model, model_dir): +def save_model(model: Module, model_dir_path: Path) -> None: logger.info("Save the model.") - path = os.path.join(model_dir, "model.pth") + path = os.path.join(model_dir_path, "model.pth") torch.save(model.cpu().state_dict(), path) diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/test.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/test.py index a76c0fb7e6..229578b69d 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/test.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/test.py @@ -2,15 +2,15 @@ import torch import torch.nn.functional as F # noqa: N812 -import torch.utils.data -import torch.utils.data.distributed +from torch.nn import Module +from torch.utils.data import DataLoader logger = logging.getLogger(__name__) -def test(model, test_loader, device): +def test(model: Module, test_loader: DataLoader, device: str | torch.device) -> None: model.eval() - test_loss = 0 + test_loss = 0.0 correct = 0 with torch.no_grad(): for data, target in test_loader: diff --git a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/train.py b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/train.py index 93cef1439b..64bd81f461 100644 --- a/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/train.py +++ b/cloud-platform/aws/amazon-sagemaker/pytorch-mnist/src/utils/train.py @@ -1,5 +1,7 @@ +import argparse import logging import os +from pathlib import Path import torch import torch.distributed as dist @@ -17,7 +19,7 @@ logger = logging.getLogger(__name__) -def train(args): +def train(args: argparse.Namespace) -> None: is_distributed = len(args.hosts) > 1 and args.backend is not None logger.info(f"Distributed training: {is_distributed}") @@ -90,4 +92,4 @@ def train(args): f"Train Epoch: {epoch} [{batch_idx * len(device_data)}/{len(train_loader.sampler)} ({100.0 * batch_idx / len(train_loader):.0f}%)] Loss: {loss.item():.6f}", ) test(model, test_loader, device) - save_model(model, args.model_dir) + save_model(model, Path(args.model_dir)) diff --git a/cloud-platform/aws/aws-parallelcluster/pcluster/dummy_test.py b/cloud-platform/aws/aws-parallelcluster/pcluster/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-platform/aws/aws-parallelcluster/pcluster/dummy_test.py +++ b/cloud-platform/aws/aws-parallelcluster/pcluster/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/cloud-security/hm-prowler/dummy_test.py b/cloud-security/hm-prowler/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/cloud-security/hm-prowler/dummy_test.py +++ b/cloud-security/hm-prowler/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/hm-imagebind/src/dummy_test.py b/computer-vision/hm-imagebind/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/computer-vision/hm-imagebind/src/dummy_test.py +++ b/computer-vision/hm-imagebind/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/hm-imagebind/src/main.py b/computer-vision/hm-imagebind/src/main.py index 4883d98fbf..a26d61f69d 100644 --- a/computer-vision/hm-imagebind/src/main.py +++ b/computer-vision/hm-imagebind/src/main.py @@ -1,11 +1,11 @@ import logging from pathlib import Path -from typing import Any import gradio as gr import httpx import lancedb import lancedb.embeddings.imagebind +import torch from lancedb.embeddings import get_registry from lancedb.pydantic import LanceModel, Vector from lancedb.table import Table @@ -41,7 +41,7 @@ class MultimodalSearchSchema(LanceModel): class ImageBindSearch: - def __init__(self): + def __init__(self) -> None: self.table: Table | None = None @staticmethod @@ -89,7 +89,7 @@ def initialize_database( ) self.table.add(inputs) - def search_by_image(self, input_image: Any) -> tuple[str, Path]: + def search_by_image(self, input_image: torch.Tensor) -> tuple[str, Path]: if self.table is None: msg = "Database not initialized. Call initialize_database first." raise RuntimeError( @@ -115,7 +115,7 @@ def search_by_text(self, input_text: str) -> tuple[Path, Path]: ) return Path(result.image_path), Path(result.audio_path) - def search_by_audio(self, input_audio: Any) -> tuple[Path, str]: + def search_by_audio(self, input_audio: torch.Tensor) -> tuple[Path, str]: if self.table is None: msg = "Database not initialized. Call initialize_database first." raise RuntimeError( diff --git a/computer-vision/hm-open3d/src/dummy_test.py b/computer-vision/hm-open3d/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/computer-vision/hm-open3d/src/dummy_test.py +++ b/computer-vision/hm-open3d/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/hm-open3d/src/main.py b/computer-vision/hm-open3d/src/main.py index acd8fb5425..9cff3417a0 100644 --- a/computer-vision/hm-open3d/src/main.py +++ b/computer-vision/hm-open3d/src/main.py @@ -2,7 +2,7 @@ import open3d as o3d -def main(): +def main() -> None: ply_point_cloud = o3d.data.PLYPointCloud() pcd = o3d.io.read_point_cloud(ply_point_cloud.path) print(pcd) diff --git a/computer-vision/hm-pyvista/mount-saint-helens/src/dummy_test.py b/computer-vision/hm-pyvista/mount-saint-helens/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/computer-vision/hm-pyvista/mount-saint-helens/src/dummy_test.py +++ b/computer-vision/hm-pyvista/mount-saint-helens/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/hm-supervision/detect-objects/src/dummy_test.py b/computer-vision/hm-supervision/detect-objects/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/computer-vision/hm-supervision/detect-objects/src/dummy_test.py +++ b/computer-vision/hm-supervision/detect-objects/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/open-clip/src/dummy_test.py b/computer-vision/open-clip/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/computer-vision/open-clip/src/dummy_test.py +++ b/computer-vision/open-clip/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/computer-vision/open-clip/src/main.py b/computer-vision/open-clip/src/main.py index ce68460a8e..75f4345dbb 100644 --- a/computer-vision/open-clip/src/main.py +++ b/computer-vision/open-clip/src/main.py @@ -27,7 +27,7 @@ class Pets(LanceModel): image_uri: str = EMBEDDINGS.SourceField() -def main(): +def main() -> None: db = lancedb.connect("data/lancedb") # Create or get the table diff --git a/data-analytics/hm-cudf/src/dummy_test.py b/data-analytics/hm-cudf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-cudf/src/dummy_test.py +++ b/data-analytics/hm-cudf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-cupy/src/dummy_test.py b/data-analytics/hm-cupy/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-cupy/src/dummy_test.py +++ b/data-analytics/hm-cupy/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-geopandas/src/dummy_test.py b/data-analytics/hm-geopandas/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-geopandas/src/dummy_test.py +++ b/data-analytics/hm-geopandas/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-networkx/src/dummy_test.py b/data-analytics/hm-networkx/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-networkx/src/dummy_test.py +++ b/data-analytics/hm-networkx/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-numba/src/dummy_test.py b/data-analytics/hm-numba/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-numba/src/dummy_test.py +++ b/data-analytics/hm-numba/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-pandas/src/dummy_test.py b/data-analytics/hm-pandas/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-pandas/src/dummy_test.py +++ b/data-analytics/hm-pandas/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-analytics/hm-polars/src/dummy_test.py b/data-analytics/hm-polars/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-analytics/hm-polars/src/dummy_test.py +++ b/data-analytics/hm-polars/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-distribution-service/dummy_test.py b/data-distribution-service/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-distribution-service/dummy_test.py +++ b/data-distribution-service/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-distribution-service/publish.py b/data-distribution-service/publish.py index 5f85c0374e..3b2b69bef9 100644 --- a/data-distribution-service/publish.py +++ b/data-distribution-service/publish.py @@ -3,7 +3,7 @@ import rti.connextdds as dds -def publisher_main(dds_domain_id: int, total_count: int): +def publisher_main(dds_domain_id: int, total_count: int) -> None: participant = dds.DomainParticipant(domain_id=dds_domain_id) hm_type = dds.QosProvider("hm_message.xml").type("HMMessage") diff --git a/data-distribution-service/subscribe.py b/data-distribution-service/subscribe.py index 7dff1a375e..c56afc249b 100644 --- a/data-distribution-service/subscribe.py +++ b/data-distribution-service/subscribe.py @@ -4,14 +4,14 @@ class Listener(dds.DynamicData.NoOpDataReaderListener): - def on_data_available(self, reader: dds.DynamicData.DataReader): + def on_data_available(self, reader: dds.DynamicData.DataReader) -> None: with reader.take() as samples: for sample in samples: if sample.info.valid: print(sample.data) -def subscriber_main(domain_id: int): +def subscriber_main(domain_id: int) -> None: participant = dds.DomainParticipant(domain_id) hm_type = dds.QosProvider("hm_message.xml").type("HMMessage") diff --git a/data-orchestration/hm-airflow/dags/greet.py b/data-orchestration/hm-airflow/dags/greet.py index e9bc45493e..be5e3e988c 100644 --- a/data-orchestration/hm-airflow/dags/greet.py +++ b/data-orchestration/hm-airflow/dags/greet.py @@ -1,7 +1,8 @@ from datetime import datetime -from airflow import DAG from airflow.decorators import task, task_group +from airflow.models import DAG +from airflow.models.taskinstance import TaskInstance from airflow.operators.bash import BashOperator with DAG( @@ -16,7 +17,10 @@ ) as dag: @task(task_id="get_name") - def get_name(params=None) -> dict[str, str]: + def get_name(params: dict[str, str] | None = None) -> dict[str, str]: + if params is None: + msg = "params cannot be None" + raise ValueError(msg) return { "first_name": params["first_name"], "last_name": params["last_name"], @@ -40,8 +44,14 @@ def get_initials(first_name_initial: str, last_name_initial: str) -> str: ) @task - def greet(initials: str, ti=None) -> str: + def greet(initials: str, ti: TaskInstance | None = None) -> str: + if ti is None: + msg = "TaskInstance cannot be None" + raise ValueError(msg) time = ti.xcom_pull(task_ids="get_time") + if time is None: + msg = "Failed to get time from xcom" + raise ValueError(msg) dt = datetime.strptime(time, "%Y-%m-%d %H:%M:%S") return f'Hello {initials}, {dt.strftime("at %H:%M on %B %d, %Y")}!' diff --git a/data-orchestration/hm-airflow/dummy_test.py b/data-orchestration/hm-airflow/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-orchestration/hm-airflow/dummy_test.py +++ b/data-orchestration/hm-airflow/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-orchestration/hm-prefect/workflows/calculate/src/dummy_test.py b/data-orchestration/hm-prefect/workflows/calculate/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-orchestration/hm-prefect/workflows/calculate/src/dummy_test.py +++ b/data-orchestration/hm-prefect/workflows/calculate/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-orchestration/hm-prefect/workflows/greet/src/dummy_test.py b/data-orchestration/hm-prefect/workflows/greet/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-orchestration/hm-prefect/workflows/greet/src/dummy_test.py +++ b/data-orchestration/hm-prefect/workflows/greet/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-orchestration/hm-prefect/workflows/print-platform/src/dummy_test.py b/data-orchestration/hm-prefect/workflows/print-platform/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-orchestration/hm-prefect/workflows/print-platform/src/dummy_test.py +++ b/data-orchestration/hm-prefect/workflows/print-platform/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-orchestration/hm-prefect/workflows/print-platform/src/main.py b/data-orchestration/hm-prefect/workflows/print-platform/src/main.py index e83c072ca7..dfebd8f6d5 100644 --- a/data-orchestration/hm-prefect/workflows/print-platform/src/main.py +++ b/data-orchestration/hm-prefect/workflows/print-platform/src/main.py @@ -4,7 +4,7 @@ @flow -def print_platform(): +def print_platform() -> None: logger = get_run_logger() logger.info(f"Node: {platform.node()}") logger.info(f"Platform: {platform.platform()}") diff --git a/data-processing/hm-spark/applications/analyze-coffee-customers/src/dummy_test.py b/data-processing/hm-spark/applications/analyze-coffee-customers/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-processing/hm-spark/applications/analyze-coffee-customers/src/dummy_test.py +++ b/data-processing/hm-spark/applications/analyze-coffee-customers/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-processing/hm-spark/applications/find-retired-people-python/src/dummy_test.py b/data-processing/hm-spark/applications/find-retired-people-python/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-processing/hm-spark/applications/find-retired-people-python/src/dummy_test.py +++ b/data-processing/hm-spark/applications/find-retired-people-python/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/dummy_test.py b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/dummy_test.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/df_test.py b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/df_test.py index 094ea059b4..a310944848 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/df_test.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/df_test.py @@ -3,7 +3,7 @@ class TestUnionAll: - def test_with_two_dataframes(self): + def test_with_two_dataframes(self) -> None: spark = SparkSession.builder.getOrCreate() df1 = spark.createDataFrame([(1, "a"), (2, "b")], ["col1", "col2"]) df2 = spark.createDataFrame([(3, "c"), (4, "d")], ["col1", "col2"]) diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/zone.py b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/zone.py index 2a44995392..ab1551c782 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/zone.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes-sql/src/utils/zone.py @@ -1,7 +1,7 @@ from pyspark.sql import DataFrame, SparkSession -def load_zones(spark: SparkSession, zone_data_path: str): +def load_zones(spark: SparkSession, zone_data_path: str) -> DataFrame: return ( spark.read.format("csv") .option("inferSchema", True) diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes/src/dummy_test.py b/data-processing/hm-spark/applications/find-taxi-top-routes/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes/src/dummy_test.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/df_test.py b/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/df_test.py index 094ea059b4..a310944848 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/df_test.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/df_test.py @@ -3,7 +3,7 @@ class TestUnionAll: - def test_with_two_dataframes(self): + def test_with_two_dataframes(self) -> None: spark = SparkSession.builder.getOrCreate() df1 = spark.createDataFrame([(1, "a"), (2, "b")], ["col1", "col2"]) df2 = spark.createDataFrame([(3, "c"), (4, "d")], ["col1", "col2"]) diff --git a/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/zone.py b/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/zone.py index 2a44995392..ab1551c782 100644 --- a/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/zone.py +++ b/data-processing/hm-spark/applications/find-taxi-top-routes/src/utils/zone.py @@ -1,7 +1,7 @@ from pyspark.sql import DataFrame, SparkSession -def load_zones(spark: SparkSession, zone_data_path: str): +def load_zones(spark: SparkSession, zone_data_path: str) -> DataFrame: return ( spark.read.format("csv") .option("inferSchema", True) diff --git a/data-processing/hm-spark/applications/recommend-movies/src/dummy_test.py b/data-processing/hm-spark/applications/recommend-movies/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-processing/hm-spark/applications/recommend-movies/src/dummy_test.py +++ b/data-processing/hm-spark/applications/recommend-movies/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-processing/hm-spark/applications/recommend-movies/src/main.py b/data-processing/hm-spark/applications/recommend-movies/src/main.py index e85f9509f7..fcdfc25587 100644 --- a/data-processing/hm-spark/applications/recommend-movies/src/main.py +++ b/data-processing/hm-spark/applications/recommend-movies/src/main.py @@ -3,7 +3,7 @@ from pyspark.sql.functions import col, explode -def main(data_dirname: str, ratings_filename: str, movies_filename: str): +def main(data_dirname: str, ratings_filename: str, movies_filename: str) -> None: spark = SparkSession.builder.getOrCreate() ratings_df = spark.read.csv( diff --git a/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/dummy_test.py b/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/dummy_test.py +++ b/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/main.py b/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/main.py index 1ebc7e425d..b4f32c42ac 100644 --- a/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/main.py +++ b/data-storage/delta-lake/read-delta-lake-by-amazon-athena/src/main.py @@ -5,7 +5,7 @@ logger = logging.getLogger(__name__) -def main(): +def main() -> None: df = wr.athena.read_sql_query( "select * from motor limit 10;", database="production_hm_iot_db", diff --git a/data-storage/delta-lake/read-delta-lake-by-trino/src/dummy_test.py b/data-storage/delta-lake/read-delta-lake-by-trino/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/delta-lake/read-delta-lake-by-trino/src/dummy_test.py +++ b/data-storage/delta-lake/read-delta-lake-by-trino/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/delta-lake/read-delta-lake-by-trino/src/main.py b/data-storage/delta-lake/read-delta-lake-by-trino/src/main.py index af1444ab8a..99e9bf805f 100644 --- a/data-storage/delta-lake/read-delta-lake-by-trino/src/main.py +++ b/data-storage/delta-lake/read-delta-lake-by-trino/src/main.py @@ -5,7 +5,7 @@ from trino.sqlalchemy import URL -def main(): +def main() -> None: event_id = "ad7953cd-6d49-4929-8180-99555bebc255" field_names = ["current", "voltage", "temperature"] diff --git a/data-storage/delta-lake/write-to-delta-lake/src/dummy_test.py b/data-storage/delta-lake/write-to-delta-lake/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/delta-lake/write-to-delta-lake/src/dummy_test.py +++ b/data-storage/delta-lake/write-to-delta-lake/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/delta-lake/write-to-delta-lake/src/main.py b/data-storage/delta-lake/write-to-delta-lake/src/main.py index 63ba074fb3..1d108c3184 100644 --- a/data-storage/delta-lake/write-to-delta-lake/src/main.py +++ b/data-storage/delta-lake/write-to-delta-lake/src/main.py @@ -7,7 +7,7 @@ from deltalake.writer import write_deltalake -def main(row_count: int): +def main(row_count: int) -> None: generator = np.random.default_rng(42) timestamp = np.array([time.time() + i * 0.01 for i in range(row_count)]) current = generator.standard_normal(row_count) * 10.0 diff --git a/data-storage/hm-duckdb/query-duckdb/src/dummy_test.py b/data-storage/hm-duckdb/query-duckdb/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-duckdb/query-duckdb/src/dummy_test.py +++ b/data-storage/hm-duckdb/query-duckdb/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/hm-duckdb/query-lance/src/dummy_test.py b/data-storage/hm-duckdb/query-lance/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-duckdb/query-lance/src/dummy_test.py +++ b/data-storage/hm-duckdb/query-lance/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/hm-duckdb/query-parquet/src/dummy_test.py b/data-storage/hm-duckdb/query-parquet/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-duckdb/query-parquet/src/dummy_test.py +++ b/data-storage/hm-duckdb/query-parquet/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/hm-duckdb/query-protobuf/src/dummy_test.py b/data-storage/hm-duckdb/query-protobuf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-duckdb/query-protobuf/src/dummy_test.py +++ b/data-storage/hm-duckdb/query-protobuf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/hm-lancedb/src/dummy_test.py b/data-storage/hm-lancedb/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-lancedb/src/dummy_test.py +++ b/data-storage/hm-lancedb/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/hm-lancedb/src/main.py b/data-storage/hm-lancedb/src/main.py index 90199ef5ec..39e60bce6b 100644 --- a/data-storage/hm-lancedb/src/main.py +++ b/data-storage/hm-lancedb/src/main.py @@ -29,7 +29,7 @@ def perform_semantic_search(table: lancedb.table.Table, query: str) -> pl.DataFr return table.search(query).limit(5).to_polars() -def main(): +def main() -> None: url = "https://raw.githubusercontent.com/Abhiram970/RickBot/refs/heads/main/Rick_and_Morty.csv" df = pl.read_csv(url) db = lancedb.connect("data/lancedb") diff --git a/data-storage/hm-protobuf/src/dummy_test.py b/data-storage/hm-protobuf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/hm-protobuf/src/dummy_test.py +++ b/data-storage/hm-protobuf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-storage/lance/src/dummy_test.py b/data-storage/lance/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-storage/lance/src/dummy_test.py +++ b/data-storage/lance/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-transformation/dbt/projects/dbt_hm_postgres/dummy_test.py b/data-transformation/dbt/projects/dbt_hm_postgres/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-transformation/dbt/projects/dbt_hm_postgres/dummy_test.py +++ b/data-transformation/dbt/projects/dbt_hm_postgres/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-visualization/grafana/hm-dashboard/src/dummy_test.py b/data-visualization/grafana/hm-dashboard/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-visualization/grafana/hm-dashboard/src/dummy_test.py +++ b/data-visualization/grafana/hm-dashboard/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-visualization/iads/iads-data-manager/iads-config-reader/src/dummy_test.py b/data-visualization/iads/iads-data-manager/iads-config-reader/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-visualization/iads/iads-data-manager/iads-config-reader/src/dummy_test.py +++ b/data-visualization/iads/iads-data-manager/iads-config-reader/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-visualization/iads/iads-data-manager/iads-config-reader/src/main.py b/data-visualization/iads/iads-data-manager/iads-config-reader/src/main.py index 0fead7a801..aad264cb6c 100644 --- a/data-visualization/iads/iads-data-manager/iads-config-reader/src/main.py +++ b/data-visualization/iads/iads-data-manager/iads-config-reader/src/main.py @@ -8,7 +8,7 @@ logger = logging.getLogger(__name__) -def show_version_from_file(iads_config: Any, iads_config_path: Path) -> None: +def show_version_from_file(iads_config: Any, iads_config_path: Path) -> None: # noqa: ANN401 try: version = iads_config.VersionFromFile(iads_config_path) logger.info(f"{version = }") @@ -16,7 +16,7 @@ def show_version_from_file(iads_config: Any, iads_config_path: Path) -> None: logger.exception(f"{iads_config_path = }") -def execute_query(iads_config: Any, query: str) -> None: +def execute_query(iads_config: Any, query: str) -> None: # noqa: ANN401 try: logger.info(f"{query = }") results: list[Any] | None = iads_config.Query(query) diff --git a/data-visualization/iads/iads-data-manager/iads-data-reader/src/dummy_test.py b/data-visualization/iads/iads-data-manager/iads-data-reader/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/data-visualization/iads/iads-data-manager/iads-data-reader/src/dummy_test.py +++ b/data-visualization/iads/iads-data-manager/iads-data-reader/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/data-visualization/iads/iads-data-manager/iads-data-reader/src/main.py b/data-visualization/iads/iads-data-manager/iads-data-reader/src/main.py index 4787c05930..0e59ca4eea 100644 --- a/data-visualization/iads/iads-data-manager/iads-data-reader/src/main.py +++ b/data-visualization/iads/iads-data-manager/iads-data-reader/src/main.py @@ -23,7 +23,7 @@ class IadsUtil: PARQUET_ZSTD_COMPRESSION_LEVEL = 19 @staticmethod - def get_iads_signals(iads_config: Any, query: str) -> set[str]: + def get_iads_signals(iads_config: Any, query: str) -> set[str]: # noqa: ANN401 logger.info(f"Executing: {query}") results = iads_config.Query(query) if not results: @@ -38,7 +38,7 @@ def get_iads_signals(iads_config: Any, query: str) -> set[str]: @staticmethod def create_iads_signal_group( - iads_config: Any, + iads_config: Any, # noqa: ANN401 signal_set: set[str], group_name: str, ) -> None: diff --git a/embedded-systems/decode-can-data/src/dummy_test.py b/embedded-systems/decode-can-data/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/embedded-systems/decode-can-data/src/dummy_test.py +++ b/embedded-systems/decode-can-data/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/embedded-systems/decode-can-data/src/main.py b/embedded-systems/decode-can-data/src/main.py index d99490906f..1a4f2bd84d 100644 --- a/embedded-systems/decode-can-data/src/main.py +++ b/embedded-systems/decode-can-data/src/main.py @@ -113,8 +113,8 @@ def initialize_schema_dict( @staticmethod def initialize_writer_dict( schema_dict: dict[str, pa.Schema], - parquet_compression_method, - parquet_compression_level, + parquet_compression_method: str, + parquet_compression_level: int, output_dir: Path, ) -> dict[str, pq.ParquetWriter]: writer_dict = {} diff --git a/embedded-systems/format-can-data/src/dummy_test.py b/embedded-systems/format-can-data/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/embedded-systems/format-can-data/src/dummy_test.py +++ b/embedded-systems/format-can-data/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/embedded-systems/hm-serial/src/dummy_test.py b/embedded-systems/hm-serial/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/embedded-systems/hm-serial/src/dummy_test.py +++ b/embedded-systems/hm-serial/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/embedded-systems/pack-unpack-data/src/dummy_test.py b/embedded-systems/pack-unpack-data/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/embedded-systems/pack-unpack-data/src/dummy_test.py +++ b/embedded-systems/pack-unpack-data/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hardware-in-the-loop/national-instruments/hm-pyvisa/src/dummy_test.py b/hardware-in-the-loop/national-instruments/hm-pyvisa/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/hardware-in-the-loop/national-instruments/hm-pyvisa/src/dummy_test.py +++ b/hardware-in-the-loop/national-instruments/hm-pyvisa/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hardware-in-the-loop/national-instruments/hm-tdms/src/dummy_test.py b/hardware-in-the-loop/national-instruments/hm-tdms/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/hardware-in-the-loop/national-instruments/hm-tdms/src/dummy_test.py +++ b/hardware-in-the-loop/national-instruments/hm-tdms/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/dummy_test.py b/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/dummy_test.py +++ b/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/main.py b/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/main.py index f4fd4a1812..d0fe20fa93 100644 --- a/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/main.py +++ b/hardware-in-the-loop/national-instruments/veristand/hm-veristand/src/main.py @@ -6,7 +6,7 @@ @nivs_rt_sequence @NivsParam("engine_power", BooleanValue(0), NivsParam.BY_REF) @NivsParam("desired_rpm", DoubleValue(0), NivsParam.BY_REF) -def engine_demo_basic(engine_power, desired_rpm) -> None: +def engine_demo_basic(engine_power, desired_rpm) -> None: # noqa: ANN001 engine_power_chan = ChannelReference("Aliases/EnginePower") desired_rpm_chan = ChannelReference("Aliases/DesiredRPM") engine_power_chan.value = engine_power.value diff --git a/high-performance-computing/hm-jax/src/dummy_test.py b/high-performance-computing/hm-jax/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/high-performance-computing/hm-jax/src/dummy_test.py +++ b/high-performance-computing/hm-jax/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hm-locust/src/dummy_test.py b/hm-locust/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/hm-locust/src/dummy_test.py +++ b/hm-locust/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/hm-locust/src/main.py b/hm-locust/src/main.py index 069b98c3d2..5f971a7833 100644 --- a/hm-locust/src/main.py +++ b/hm-locust/src/main.py @@ -10,7 +10,7 @@ class WebsiteUser(HttpUser): wait_time = between(5, 15) jwt_token = "" - def on_start(self): + def on_start(self) -> None: res = self.client.get("/", verify=False) # Get JWT token @@ -33,11 +33,11 @@ def on_start(self): self.jwt_token = content["data"]["signIn"]["jwtToken"] @task - def index(self): + def index(self) -> None: self.client.get("/", verify=False) @task - def fetch_me(self): + def fetch_me(self) -> None: query = """ query Me { me { @@ -50,7 +50,7 @@ def fetch_me(self): self.client.post("/graphql", json={"query": query}, verify=False) @task - def upload_file(self): + def upload_file(self) -> None: file_path = "src/fixture/image.png" file_name = os.path.basename(file_path) file = open(file_path, "rb") diff --git a/hm-xxhash/src/dummy_test.py b/hm-xxhash/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/hm-xxhash/src/dummy_test.py +++ b/hm-xxhash/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/convolutional-neural-network/src/args.py b/machine-learning/convolutional-neural-network/src/args.py index 4e54792e87..6bf2ca5da8 100644 --- a/machine-learning/convolutional-neural-network/src/args.py +++ b/machine-learning/convolutional-neural-network/src/args.py @@ -1,7 +1,7 @@ import argparse -def get_args(): +def get_args() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument( "--should_download_original_data", diff --git a/machine-learning/convolutional-neural-network/src/dummy_test.py b/machine-learning/convolutional-neural-network/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/convolutional-neural-network/src/dummy_test.py +++ b/machine-learning/convolutional-neural-network/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/convolutional-neural-network/src/evaluate.py b/machine-learning/convolutional-neural-network/src/evaluate.py index 3ed1f19a0f..2f7db0c011 100644 --- a/machine-learning/convolutional-neural-network/src/evaluate.py +++ b/machine-learning/convolutional-neural-network/src/evaluate.py @@ -1,7 +1,9 @@ import torch +from torch import nn +from torch.utils.data import DataLoader -def evaluate(net, data_loader, device): +def evaluate(net: nn.Module, data_loader: DataLoader, device: str) -> float: net.eval() correct = 0 total = 0 diff --git a/machine-learning/convolutional-neural-network/src/main.py b/machine-learning/convolutional-neural-network/src/main.py index 5325840234..21120bd99f 100644 --- a/machine-learning/convolutional-neural-network/src/main.py +++ b/machine-learning/convolutional-neural-network/src/main.py @@ -10,7 +10,7 @@ from utils.writer import write_params -def main(): +def main() -> None: with open("params.yaml") as f: params = yaml.safe_load(f) diff --git a/machine-learning/convolutional-neural-network/src/model/net.py b/machine-learning/convolutional-neural-network/src/model/net.py index 37c0ce88d9..8e47f751f3 100644 --- a/machine-learning/convolutional-neural-network/src/model/net.py +++ b/machine-learning/convolutional-neural-network/src/model/net.py @@ -4,7 +4,7 @@ class Net(nn.Module): - def __init__(self): + def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(3, 6, 5) self.pool = nn.MaxPool2d(2, 2) @@ -13,7 +13,7 @@ def __init__(self): self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, 10) - def forward(self, x): + def forward(self, x: torch.Tensor) -> torch.Tensor: x = self.pool(F.relu(self.conv1(x))) x = self.pool(F.relu(self.conv2(x))) x = torch.flatten(x, 1) # flatten all dimensions except batch diff --git a/machine-learning/convolutional-neural-network/src/train.py b/machine-learning/convolutional-neural-network/src/train.py index 55347398c5..cb25b3de57 100644 --- a/machine-learning/convolutional-neural-network/src/train.py +++ b/machine-learning/convolutional-neural-network/src/train.py @@ -1,4 +1,15 @@ -def train(net, data_loader, device, optimizer, criterion): +from torch import nn +from torch.optim import Optimizer +from torch.utils.data import DataLoader + + +def train( + net: nn.Module, + data_loader: DataLoader, + device: str, + optimizer: Optimizer, + criterion: nn.Module, +) -> float: net.train() running_loss = 0.0 diff --git a/machine-learning/convolutional-neural-network/src/utils/writer.py b/machine-learning/convolutional-neural-network/src/utils/writer.py index 5f28d45a94..5580374e45 100644 --- a/machine-learning/convolutional-neural-network/src/utils/writer.py +++ b/machine-learning/convolutional-neural-network/src/utils/writer.py @@ -1,7 +1,9 @@ +from typing import Any + import pandas as pd -def write_params(params): +def write_params(params: dict[str, Any]) -> None: df = pd.DataFrame.from_dict(params, orient="index", columns=["Value"]) with open("output/reports/params.txt", "w") as f: f.write(df.to_markdown()) diff --git a/machine-learning/dali/src/dummy_test.py b/machine-learning/dali/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/dali/src/dummy_test.py +++ b/machine-learning/dali/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/dali/src/main.py b/machine-learning/dali/src/main.py index 9790cf32be..0964d223a0 100644 --- a/machine-learning/dali/src/main.py +++ b/machine-learning/dali/src/main.py @@ -4,6 +4,7 @@ import torch from nvidia.dali import fn, pipeline_def, types +from nvidia.dali.pipeline import Pipeline from nvidia.dali.plugin.pytorch import DALIGenericIterator logger = logging.getLogger(__name__) @@ -34,7 +35,7 @@ def download_sample_images(data_path: Path) -> None: @pipeline_def(batch_size=2, num_threads=2, device_id=None) -def image_pipeline(data_path: Path): +def image_pipeline(data_path: Path) -> Pipeline: jpegs, labels = fn.readers.file( file_root=data_path, random_shuffle=True, diff --git a/machine-learning/feature-store/dummy_test.py b/machine-learning/feature-store/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/feature-store/dummy_test.py +++ b/machine-learning/feature-store/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/graph-neural-network/src/args.py b/machine-learning/graph-neural-network/src/args.py index 09d3a03661..17c2e64dea 100644 --- a/machine-learning/graph-neural-network/src/args.py +++ b/machine-learning/graph-neural-network/src/args.py @@ -1,7 +1,7 @@ import argparse -def get_args(): +def get_args() -> argparse.Namespace: parser = argparse.ArgumentParser( description="GNN baselines on ogbgmol* data with Pytorch Geometrics", ) diff --git a/machine-learning/graph-neural-network/src/dummy_test.py b/machine-learning/graph-neural-network/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/graph-neural-network/src/dummy_test.py +++ b/machine-learning/graph-neural-network/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/graph-neural-network/src/main.py b/machine-learning/graph-neural-network/src/main.py index b8dd4931dc..0e77775c4f 100644 --- a/machine-learning/graph-neural-network/src/main.py +++ b/machine-learning/graph-neural-network/src/main.py @@ -5,14 +5,21 @@ from model.data_loader import fetch_dataset, get_dataloaders from model.gnn import GNN from ogb.graphproppred import Evaluator -from torch import optim +from torch import nn, optim +from torch.utils.data import DataLoader from tqdm import tqdm cls_criterion = torch.nn.BCEWithLogitsLoss() reg_criterion = torch.nn.MSELoss() -def train(model, device, loader, optimizer, task_type): +def train( + model: nn.Module, + device: str, + loader: DataLoader, + optimizer: torch.optim.Optimizer, + task_type: str, +) -> float: model.train() total_loss = 0 @@ -43,7 +50,9 @@ def train(model, device, loader, optimizer, task_type): return total_loss -def evaluate(model, device, loader, evaluator): +def evaluate( + model: nn.Module, device: str, loader: DataLoader, evaluator: Evaluator +) -> dict: model.eval() y_true = [] y_pred = [] @@ -68,7 +77,7 @@ def evaluate(model, device, loader, evaluator): return evaluator.eval(input_dict) -def main(): +def main() -> None: # Training settings args = get_args() diff --git a/machine-learning/graph-neural-network/src/model/conv.py b/machine-learning/graph-neural-network/src/model/conv.py index 1a57a9ff37..58a032666c 100644 --- a/machine-learning/graph-neural-network/src/model/conv.py +++ b/machine-learning/graph-neural-network/src/model/conv.py @@ -1,13 +1,15 @@ import torch import torch.nn.functional as F # noqa: N812 from ogb.graphproppred.mol_encoder import AtomEncoder, BondEncoder +from torch import Tensor +from torch_geometric.data import Data from torch_geometric.nn import MessagePassing, global_add_pool from torch_geometric.utils import degree # GIN convolution along the graph structure class GINConv(MessagePassing): - def __init__(self, emb_dim): + def __init__(self, emb_dim: int) -> None: super().__init__(aggr="add") self.mlp = torch.nn.Sequential( torch.nn.Linear(emb_dim, 2 * emb_dim), @@ -18,7 +20,7 @@ def __init__(self, emb_dim): self.eps = torch.nn.Parameter(torch.Tensor([0])) self.bond_encoder = BondEncoder(emb_dim=emb_dim) - def forward(self, x, edge_index, edge_attr): + def forward(self, x: Tensor, edge_index: Tensor, edge_attr: Tensor) -> Tensor: edge_embedding = self.bond_encoder(edge_attr) out = self.mlp( (1 + self.eps) * x @@ -26,22 +28,22 @@ def forward(self, x, edge_index, edge_attr): ) return out - def message(self, x_j, edge_attr): + def message(self, x_j: Tensor, edge_attr: Tensor) -> Tensor: return F.relu(x_j + edge_attr) - def update(self, aggr_out): + def update(self, aggr_out: Tensor) -> Tensor: return aggr_out # GCN convolution along the graph structure class GCNConv(MessagePassing): - def __init__(self, emb_dim): + def __init__(self, emb_dim: int) -> None: super().__init__(aggr="add") self.linear = torch.nn.Linear(emb_dim, emb_dim) self.root_emb = torch.nn.Embedding(1, emb_dim) self.bond_encoder = BondEncoder(emb_dim=emb_dim) - def forward(self, x, edge_index, edge_attr): + def forward(self, x: Tensor, edge_index: Tensor, edge_attr: Tensor) -> Tensor: # x: [N, in_channels] # edge_index: [2, E] # edge_attr: [E, 2] @@ -64,12 +66,12 @@ def forward(self, x, edge_index, edge_attr): norm=norm, ) + F.relu(x + self.root_emb.weight) * 1.0 / deg.view(-1, 1) - def message(self, x_j, edge_attr, norm): + def message(self, x_j: Tensor, edge_attr: Tensor, norm: Tensor) -> Tensor: # x_j: [E, out_channels] # edge_attr: [E, out_channels] return norm.view(-1, 1) * F.relu(x_j + edge_attr) - def update(self, aggr_out): + def update(self, aggr_out: Tensor) -> Tensor: # aggr_out: [N, out_channels] return aggr_out @@ -77,13 +79,13 @@ def update(self, aggr_out): class GNNNode(torch.nn.Module): def __init__( self, - num_layer, - emb_dim, - drop_ratio=0.5, - jk="last", - residual=False, - gnn_type="gin", - ): + num_layer: int, + emb_dim: int, + drop_ratio: float = 0.5, + jk: str = "last", + residual: bool = False, + gnn_type: str = "gin", + ) -> None: super().__init__() self.num_layer = num_layer self.drop_ratio = drop_ratio @@ -112,7 +114,7 @@ def __init__( self.batch_norms.append(torch.nn.BatchNorm1d(emb_dim)) - def forward(self, batched_data): + def forward(self, batched_data: Data) -> torch.Tensor: x, edge_index, edge_attr = ( batched_data.x, batched_data.edge_index, @@ -151,13 +153,13 @@ def forward(self, batched_data): class GNNVirtualNode(torch.nn.Module): def __init__( self, - num_layer, - emb_dim, - drop_ratio=0.5, - jk="last", - residual=False, - gnn_type="gin", - ): + num_layer: int, + emb_dim: int, + drop_ratio: float = 0.5, + jk: str = "last", + residual: bool = False, + gnn_type: str = "gin", + ) -> None: super().__init__() self.num_layer = num_layer self.drop_ratio = drop_ratio @@ -206,7 +208,7 @@ def __init__( ), ) - def forward(self, batched_data): + def forward(self, batched_data: Data) -> torch.Tensor: x, edge_index, edge_attr, batch = ( batched_data.x, batched_data.edge_index, diff --git a/machine-learning/graph-neural-network/src/model/data_loader.py b/machine-learning/graph-neural-network/src/model/data_loader.py index 8f41bc3edb..220fc8dc38 100644 --- a/machine-learning/graph-neural-network/src/model/data_loader.py +++ b/machine-learning/graph-neural-network/src/model/data_loader.py @@ -1,8 +1,11 @@ +import argparse + +import torch from ogb.graphproppred import PygGraphPropPredDataset from torch_geometric.loader import DataLoader -def fetch_dataset(config): +def fetch_dataset(config: argparse.Namespace) -> PygGraphPropPredDataset: # automatic data loading and splitting dataset = PygGraphPropPredDataset(name=config.dataset) @@ -19,7 +22,11 @@ def fetch_dataset(config): return dataset, split_idx -def get_dataloaders(dataset, split_idx, config): +def get_dataloaders( + dataset: PygGraphPropPredDataset, + split_idx: dict[str, torch.Tensor], + config: argparse.Namespace, +) -> dict[str, DataLoader]: train_loader = DataLoader( dataset[split_idx["train"]], batch_size=config.batch_size, diff --git a/machine-learning/graph-neural-network/src/model/gnn.py b/machine-learning/graph-neural-network/src/model/gnn.py index 1385d472d1..2201719d8d 100644 --- a/machine-learning/graph-neural-network/src/model/gnn.py +++ b/machine-learning/graph-neural-network/src/model/gnn.py @@ -1,5 +1,7 @@ import torch from model.conv import GNNNode, GNNVirtualNode +from torch import Tensor +from torch_geometric.data import Data from torch_geometric.nn import ( GlobalAttention, Set2Set, @@ -12,16 +14,16 @@ class GNN(torch.nn.Module): def __init__( self, - num_tasks, - num_layer=5, - emb_dim=300, - gnn_type="gin", - virtual_node=True, - residual=False, - drop_ratio=0.5, - jk="last", - graph_pooling="mean", - ): + num_tasks: int, + num_layer: int = 5, + emb_dim: int = 300, + gnn_type: str = "gin", + virtual_node: bool = True, + residual: bool = False, + drop_ratio: float = 0.5, + jk: str = "last", + graph_pooling: str = "mean", + ) -> None: super().__init__() self.num_layer = num_layer @@ -82,7 +84,7 @@ def __init__( else: self.graph_pred_linear = torch.nn.Linear(self.emb_dim, self.num_tasks) - def forward(self, batched_data): + def forward(self, batched_data: Data) -> Tensor: h_node = self.gnn_node(batched_data) h_graph = self.pool(h_node, batched_data.batch) return self.graph_pred_linear(h_graph) diff --git a/machine-learning/hm-autogluon/src/dummy_test.py b/machine-learning/hm-autogluon/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-autogluon/src/dummy_test.py +++ b/machine-learning/hm-autogluon/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-docling/src/dummy_test.py b/machine-learning/hm-docling/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-docling/src/dummy_test.py +++ b/machine-learning/hm-docling/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-faster-whisper/src/dummy_test.py b/machine-learning/hm-faster-whisper/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-faster-whisper/src/dummy_test.py +++ b/machine-learning/hm-faster-whisper/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-flax/src/dummy_test.py b/machine-learning/hm-flax/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-flax/src/dummy_test.py +++ b/machine-learning/hm-flax/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-flax/src/main.py b/machine-learning/hm-flax/src/main.py index 6e78ca0062..1c958c8656 100644 --- a/machine-learning/hm-flax/src/main.py +++ b/machine-learning/hm-flax/src/main.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Callable import flax.linen as nn import jax @@ -40,7 +40,7 @@ def cross_entropy_loss(logits: jnp.ndarray, labels: jnp.ndarray) -> jnp.ndarray: def loss_fn( params: dict[str, Any], - apply_fn: Any, + apply_fn: Callable[[dict[str, Any], jnp.ndarray], jnp.ndarray], images: jnp.ndarray, labels: jnp.ndarray, ) -> tuple[jnp.ndarray, jnp.ndarray]: diff --git a/machine-learning/hm-gradio/applications/classify-image/src/dummy_test.py b/machine-learning/hm-gradio/applications/classify-image/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-gradio/applications/classify-image/src/dummy_test.py +++ b/machine-learning/hm-gradio/applications/classify-image/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-kubeflow/pipelines/calculate/src/dummy_test.py b/machine-learning/hm-kubeflow/pipelines/calculate/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-kubeflow/pipelines/calculate/src/dummy_test.py +++ b/machine-learning/hm-kubeflow/pipelines/calculate/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-kubeflow/pipelines/calculate/src/main.py b/machine-learning/hm-kubeflow/pipelines/calculate/src/main.py index bf606152a4..7b8344038d 100644 --- a/machine-learning/hm-kubeflow/pipelines/calculate/src/main.py +++ b/machine-learning/hm-kubeflow/pipelines/calculate/src/main.py @@ -12,7 +12,7 @@ def multiply(a: int, b: int) -> int: @dsl.pipeline -def calculate(a: int, b: int): +def calculate(a: int, b: int) -> None: add_task = add(a=a, b=b) multiply(a=add_task.output, b=10) diff --git a/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/dummy_test.py b/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/dummy_test.py +++ b/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/main.py b/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/main.py index e719eabe50..09563ec454 100644 --- a/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/main.py +++ b/machine-learning/hm-kubeflow/pipelines/classify-mnist/src/main.py @@ -5,7 +5,7 @@ base_image="docker.io/python:3.10", packages_to_install=["torch==2.0.0", "torchvision==0.15.1", "lightning==2.0.5"], ) -def train(): +def train() -> None: import lightning as L # noqa: N812 import torch import torch.nn.functional as F # noqa: N812 @@ -14,7 +14,7 @@ def train(): from torch.utils import data class LitAutoEncoder(L.LightningModule): - def __init__(self): + def __init__(self) -> None: super().__init__() self.encoder = nn.Sequential( nn.Linear(28 * 28, 128), @@ -27,11 +27,13 @@ def __init__(self): nn.Linear(128, 28 * 28), ) - def forward(self, x): + def forward(self, x: torch.Tensor) -> torch.Tensor: embedding = self.encoder(x) return embedding - def training_step(self, batch, batch_idx): + def training_step( + self, batch: tuple[torch.Tensor, torch.Tensor], batch_idx: int + ) -> torch.Tensor: x, y = batch x = x.view(x.size(0), -1) z = self.encoder(x) @@ -40,7 +42,7 @@ def training_step(self, batch, batch_idx): self.log("train_loss", loss) return loss - def configure_optimizers(self): + def configure_optimizers(self) -> torch.optim.Optimizer: optimizer = torch.optim.Adam(self.parameters(), lr=1e-3) return optimizer @@ -71,7 +73,7 @@ def configure_optimizers(self): @dsl.pipeline -def classify_fashion_mnist(): +def classify_fashion_mnist() -> None: train() diff --git a/machine-learning/hm-langchain/applications/chat-pdf/src/dummy_test.py b/machine-learning/hm-langchain/applications/chat-pdf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-langchain/applications/chat-pdf/src/dummy_test.py +++ b/machine-learning/hm-langchain/applications/chat-pdf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-langgraph/applications/chat-pdf/src/dummy_test.py b/machine-learning/hm-langgraph/applications/chat-pdf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-langgraph/applications/chat-pdf/src/dummy_test.py +++ b/machine-learning/hm-langgraph/applications/chat-pdf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-llama-index/applications/chat-pdf/src/dummy_test.py b/machine-learning/hm-llama-index/applications/chat-pdf/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-llama-index/applications/chat-pdf/src/dummy_test.py +++ b/machine-learning/hm-llama-index/applications/chat-pdf/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-mlflow/experiments/classify-mnist/src/args.py b/machine-learning/hm-mlflow/experiments/classify-mnist/src/args.py index 1cf147f2f7..27e7a424eb 100644 --- a/machine-learning/hm-mlflow/experiments/classify-mnist/src/args.py +++ b/machine-learning/hm-mlflow/experiments/classify-mnist/src/args.py @@ -1,7 +1,7 @@ import argparse -def get_args(): +def get_args() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument("--max_epochs", type=int, default=5) return parser.parse_args() diff --git a/machine-learning/hm-mlflow/experiments/classify-mnist/src/dummy_test.py b/machine-learning/hm-mlflow/experiments/classify-mnist/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-mlflow/experiments/classify-mnist/src/dummy_test.py +++ b/machine-learning/hm-mlflow/experiments/classify-mnist/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-mlflow/experiments/classify-mnist/src/main.py b/machine-learning/hm-mlflow/experiments/classify-mnist/src/main.py index 2d64b19d3b..a65b4bfdb5 100644 --- a/machine-learning/hm-mlflow/experiments/classify-mnist/src/main.py +++ b/machine-learning/hm-mlflow/experiments/classify-mnist/src/main.py @@ -10,7 +10,7 @@ class LitAutoEncoder(L.LightningModule): - def __init__(self): + def __init__(self) -> None: super().__init__() self.encoder = nn.Sequential( nn.Linear(28 * 28, 128), @@ -23,11 +23,13 @@ def __init__(self): nn.Linear(128, 28 * 28), ) - def forward(self, x): + def forward(self, x: torch.Tensor) -> torch.Tensor: embedding = self.encoder(x) return embedding - def training_step(self, batch, batch_idx): + def training_step( + self, batch: tuple[torch.Tensor, torch.Tensor], batch_idx: int + ) -> torch.Tensor: x, y = batch x = x.view(x.size(0), -1) z = self.encoder(x) @@ -36,12 +38,12 @@ def training_step(self, batch, batch_idx): self.log("train_loss", loss) return loss - def configure_optimizers(self): + def configure_optimizers(self) -> torch.optim.Optimizer: optimizer = torch.optim.Adam(self.parameters(), lr=1e-3) return optimizer -def main(): +def main() -> None: project_name = "classify-mnist" # W&B diff --git a/machine-learning/hm-mlflow/experiments/predict-diabetes/src/dummy_test.py b/machine-learning/hm-mlflow/experiments/predict-diabetes/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-mlflow/experiments/predict-diabetes/src/dummy_test.py +++ b/machine-learning/hm-mlflow/experiments/predict-diabetes/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-mlflow/experiments/predict-diabetes/src/main.py b/machine-learning/hm-mlflow/experiments/predict-diabetes/src/main.py index 69337eb4ad..c81e04d1d4 100644 --- a/machine-learning/hm-mlflow/experiments/predict-diabetes/src/main.py +++ b/machine-learning/hm-mlflow/experiments/predict-diabetes/src/main.py @@ -9,7 +9,7 @@ logger = logging.getLogger(__name__) -def main(): +def main() -> None: mlflow.set_tracking_uri(config.MLFLOW_TRACKING_SERVER_URL) mlflow.set_experiment(config.MLFLOW_EXPERIMENT_NAME) diff --git a/machine-learning/hm-rasa/actions/actions.py b/machine-learning/hm-rasa/actions/actions.py index 5662aec352..794a024eb9 100644 --- a/machine-learning/hm-rasa/actions/actions.py +++ b/machine-learning/hm-rasa/actions/actions.py @@ -51,11 +51,11 @@ def name(self) -> str: def validate_pizza_size( self, - slot_value: Any, + slot_value: str, dispatcher: CollectingDispatcher, tracker: Tracker, domain: DomainDict, - ) -> dict[str, Any]: + ) -> dict[str, str | None]: if slot_value.lower() not in ALLOWED_PIZZA_SIZES: dispatcher.utter_message( text=f"We only accept pizza sizes: {'/'.join(ALLOWED_PIZZA_SIZES)}.", @@ -66,11 +66,11 @@ def validate_pizza_size( def validate_pizza_type( self, - slot_value: Any, + slot_value: str, dispatcher: CollectingDispatcher, tracker: Tracker, domain: DomainDict, - ) -> dict[str, Any]: + ) -> dict[str, str | None]: if slot_value not in ALLOWED_PIZZA_TYPES: dispatcher.utter_message( text=f"We only serve {'/'.join(ALLOWED_PIZZA_TYPES)}.", diff --git a/machine-learning/hm-sglang/src/dummy_test.py b/machine-learning/hm-sglang/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-sglang/src/dummy_test.py +++ b/machine-learning/hm-sglang/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-streamlit/applications/live-line-chart/src/dummy_test.py b/machine-learning/hm-streamlit/applications/live-line-chart/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-streamlit/applications/live-line-chart/src/dummy_test.py +++ b/machine-learning/hm-streamlit/applications/live-line-chart/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hm-streamlit/applications/map/src/dummy_test.py b/machine-learning/hm-streamlit/applications/map/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hm-streamlit/applications/map/src/dummy_test.py +++ b/machine-learning/hm-streamlit/applications/map/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/hugging-face/analyze-sentiment/src/dummy_test.py b/machine-learning/hugging-face/analyze-sentiment/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/hugging-face/analyze-sentiment/src/dummy_test.py +++ b/machine-learning/hugging-face/analyze-sentiment/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/mineru/src/dummy_test.py b/machine-learning/mineru/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/mineru/src/dummy_test.py +++ b/machine-learning/mineru/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/neural-forecasting/forecast-air-passenger-number/src/dummy_test.py b/machine-learning/neural-forecasting/forecast-air-passenger-number/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/neural-forecasting/forecast-air-passenger-number/src/dummy_test.py +++ b/machine-learning/neural-forecasting/forecast-air-passenger-number/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/reinforcement-learning/cart-pole/src/dummy_test.py b/machine-learning/reinforcement-learning/cart-pole/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/reinforcement-learning/cart-pole/src/dummy_test.py +++ b/machine-learning/reinforcement-learning/cart-pole/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/stable-diffusion/src/dummy_test.py b/machine-learning/stable-diffusion/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/stable-diffusion/src/dummy_test.py +++ b/machine-learning/stable-diffusion/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/stable-diffusion/src/main.py b/machine-learning/stable-diffusion/src/main.py index 5b0af35164..ea33f40b29 100644 --- a/machine-learning/stable-diffusion/src/main.py +++ b/machine-learning/stable-diffusion/src/main.py @@ -95,7 +95,7 @@ def generate_images( logger.exception("Error generating images") -def main(): +def main() -> None: pipe = StableDiffusionGenerator.create_pipeline( model_id="stabilityai/stable-diffusion-2-1", is_safety_checker_enabled=True, diff --git a/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/deploy/src/dummy_test.py b/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/deploy/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/deploy/src/dummy_test.py +++ b/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/deploy/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/infer/src/dummy_test.py b/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/infer/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/infer/src/dummy_test.py +++ b/machine-learning/triton-inference-server/amazon-sagemaker-triton-resnet-50/infer/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/matlab/call-matlab-function-in-python/src/dummy_test.py b/matlab/call-matlab-function-in-python/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/matlab/call-matlab-function-in-python/src/dummy_test.py +++ b/matlab/call-matlab-function-in-python/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/parallel-computing/hm-triton/src/dummy_test.py b/parallel-computing/hm-triton/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/parallel-computing/hm-triton/src/dummy_test.py +++ b/parallel-computing/hm-triton/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/parallel-computing/hm-triton/src/main.py b/parallel-computing/hm-triton/src/main.py index 4e4e22aacb..649192cc18 100644 --- a/parallel-computing/hm-triton/src/main.py +++ b/parallel-computing/hm-triton/src/main.py @@ -9,10 +9,10 @@ @triton.jit def vector_add_kernel( - x_ptr, # Pointer to first vector - y_ptr, # Pointer to second vector - output_ptr, # Pointer to output vector - n_elements, # Number of elements in the vectors + x_ptr, # Pointer to first vector # noqa: ANN001 + y_ptr, # Pointer to second vector # noqa: ANN001 + output_ptr, # Pointer to output vector # noqa: ANN001 + n_elements: int, # Number of elements in the vectors block_size: tl.constexpr, # Number of elements each program should process ) -> None: # Program ID diff --git a/quantum-computing/src/dummy_test.py b/quantum-computing/src/dummy_test.py index 82960647c8..f746c3e9b0 100644 --- a/quantum-computing/src/dummy_test.py +++ b/quantum-computing/src/dummy_test.py @@ -1,3 +1,3 @@ class TestDummy: - def test_dummy(self): + def test_dummy(self) -> None: assert 1 + 1 == 2 diff --git a/quantum-computing/src/main.py b/quantum-computing/src/main.py index 57b64d27d9..99f60a1f6c 100644 --- a/quantum-computing/src/main.py +++ b/quantum-computing/src/main.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) -def main(): +def main() -> None: # Create a new circuit with two qubits qc = QuantumCircuit(2) diff --git a/robotics/robot-operating-system/src/hm_python_package/hm_python_package/hm_python_node.py b/robotics/robot-operating-system/src/hm_python_package/hm_python_package/hm_python_node.py index a1c5bda510..85aa190b41 100644 --- a/robotics/robot-operating-system/src/hm_python_package/hm_python_package/hm_python_node.py +++ b/robotics/robot-operating-system/src/hm_python_package/hm_python_package/hm_python_node.py @@ -3,17 +3,17 @@ class HMNode(Node): - def __init__(self): + def __init__(self) -> None: super().__init__("hm_python_node") self._count = 0 self.create_timer(0.5, self.timer_callback) - def timer_callback(self): + def timer_callback(self) -> None: self._count += 1 self.get_logger().info(f"Hello {self._count}") -def main(args=None): +def main(args: list[str] | None = None) -> None: rclpy.init(args=args) node = HMNode() rclpy.spin(node) diff --git a/robotics/robot-operating-system/src/hm_python_package/test/test_copyright.py b/robotics/robot-operating-system/src/hm_python_package/test/test_copyright.py index 6559e33e67..04b98abb5f 100644 --- a/robotics/robot-operating-system/src/hm_python_package/test/test_copyright.py +++ b/robotics/robot-operating-system/src/hm_python_package/test/test_copyright.py @@ -22,6 +22,6 @@ ) @pytest.mark.copyright @pytest.mark.linter -def test_copyright(): +def test_copyright() -> None: rc = main(argv=[".", "test"]) assert rc == 0, "Found errors" diff --git a/robotics/robot-operating-system/src/hm_python_package/test/test_flake8.py b/robotics/robot-operating-system/src/hm_python_package/test/test_flake8.py index 9e6e1222b7..7e868404e8 100644 --- a/robotics/robot-operating-system/src/hm_python_package/test/test_flake8.py +++ b/robotics/robot-operating-system/src/hm_python_package/test/test_flake8.py @@ -18,7 +18,7 @@ @pytest.mark.flake8 @pytest.mark.linter -def test_flake8(): +def test_flake8() -> None: rc, errors = main_with_errors(argv=[]) assert ( rc == 0 diff --git a/robotics/robot-operating-system/src/hm_python_package/test/test_pep257.py b/robotics/robot-operating-system/src/hm_python_package/test/test_pep257.py index 4eddb46ed1..f4905db43a 100644 --- a/robotics/robot-operating-system/src/hm_python_package/test/test_pep257.py +++ b/robotics/robot-operating-system/src/hm_python_package/test/test_pep257.py @@ -18,6 +18,6 @@ @pytest.mark.linter @pytest.mark.pep257 -def test_pep257(): +def test_pep257() -> None: rc = main(argv=[".", "test"]) assert rc == 0, "Found code style errors / warnings" diff --git a/robotics/robot-operating-system/src/turtle_robot/test/test_target_control_node.py b/robotics/robot-operating-system/src/turtle_robot/test/test_target_control_node.py index dfd58e408a..b7f80e93d9 100644 --- a/robotics/robot-operating-system/src/turtle_robot/test/test_target_control_node.py +++ b/robotics/robot-operating-system/src/turtle_robot/test/test_target_control_node.py @@ -2,29 +2,30 @@ import sys import unittest -import launch -import launch_ros -import launch_testing import pytest import rclpy +from launch import LaunchDescription +from launch_ros.actions import Node +from launch_testing.actions import ReadyToTest +from rclpy.publisher import Publisher from turtlesim.msg import Pose @pytest.mark.rostest -def generate_test_description(): +def generate_test_description() -> LaunchDescription: src_path = pathlib.Path(__file__).parent.parent - target_control_node = launch_ros.actions.Node( + target_control_node = Node( executable=sys.executable, arguments=[src_path.joinpath("turtle_robot/target_control_node.py").as_posix()], additional_env={"PYTHONUNBUFFERED": "1"}, ) return ( - launch.LaunchDescription( + LaunchDescription( [ target_control_node, - launch_testing.actions.ReadyToTest(), + ReadyToTest(), ], ), {"target_control_node": target_control_node}, @@ -33,21 +34,25 @@ def generate_test_description(): class TestTargetControlNodeLink(unittest.TestCase): @classmethod - def setUpClass(cls): + def setUpClass(cls) -> None: rclpy.init() @classmethod - def tearDownClass(cls): + def tearDownClass(cls) -> None: rclpy.shutdown() - def setUp(self): + def setUp(self) -> None: self.node = rclpy.create_node("target_control_test_node") - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() - def test_target_control_node(self, target_control_node, proc_output): - pose_pub = self.node.create_publisher(Pose, "turtle1/pose", 10) + def test_target_control_node( + self, + target_control_node: Node, + proc_output: tuple[bytes, bytes], + ) -> None: + pose_pub: Publisher = self.node.create_publisher(Pose, "turtle1/pose", 10) try: assert True diff --git a/robotics/robot-operating-system/src/turtle_robot/turtle_robot/target_control_node.py b/robotics/robot-operating-system/src/turtle_robot/turtle_robot/target_control_node.py index 75410deb6b..f1b7bc61ba 100644 --- a/robotics/robot-operating-system/src/turtle_robot/turtle_robot/target_control_node.py +++ b/robotics/robot-operating-system/src/turtle_robot/turtle_robot/target_control_node.py @@ -8,7 +8,7 @@ class TargetControlNode(Node): - def __init__(self): + def __init__(self) -> None: super().__init__("target_control_node") self.get_logger().info("target_control_node") self._target_pose = None @@ -16,10 +16,10 @@ def __init__(self): self.create_subscription(Pose, "turtle1/pose", self.subscribe_target_pose, 10) self.create_timer(1.0, self.control_loop) - def subscribe_target_pose(self, msg): + def subscribe_target_pose(self, msg: Pose) -> None: self._target_pose = msg - def control_loop(self): + def control_loop(self) -> None: if self._target_pose is None: return @@ -47,7 +47,7 @@ def control_loop(self): self._cmd_vel_publisher.publish(msg) -def main(args=None): +def main(args: list[str] | None = None) -> None: rclpy.init(args=args) node = TargetControlNode() rclpy.spin(node) diff --git a/robotics/robot-operating-system/src/turtle_robot/turtle_robot/turtle_robot_control_node.py b/robotics/robot-operating-system/src/turtle_robot/turtle_robot/turtle_robot_control_node.py index 5ef1274519..2d9cc143b1 100644 --- a/robotics/robot-operating-system/src/turtle_robot/turtle_robot/turtle_robot_control_node.py +++ b/robotics/robot-operating-system/src/turtle_robot/turtle_robot/turtle_robot_control_node.py @@ -7,12 +7,14 @@ class TurtleRobotControlNode(Node): - def __init__(self): + def __init__(self) -> None: super().__init__("turtle_robot_control_node") self.get_logger().info("turtle_robot_control_node") - self._turtle_robot_pose = None - self._target_pose = None - self._cmd_vel_publisher = self.create_publisher( + self._turtle_robot_pose: Pose | None = None + self._target_pose: Pose | None = None + from rclpy.publisher import Publisher + + self._cmd_vel_publisher: Publisher[Twist] = self.create_publisher( Twist, "turtle_robot/cmd_vel", 10, @@ -26,14 +28,14 @@ def __init__(self): self.create_subscription(Pose, "turtle1/pose", self.subscribe_target_pose, 10) self.create_timer(0.01, self.control_loop) - def subscribe_turtle_robot_pose(self, msg): + def subscribe_turtle_robot_pose(self, msg: Pose) -> None: self._turtle_robot_pose = msg - def subscribe_target_pose(self, msg): + def subscribe_target_pose(self, msg: Pose) -> None: self._target_pose = msg - def control_loop(self): - if self._turtle_robot_pose is None: + def control_loop(self) -> None: + if self._turtle_robot_pose is None or self._target_pose is None: return dist_x = self._target_pose.x - self._turtle_robot_pose.x @@ -61,7 +63,7 @@ def control_loop(self): self._cmd_vel_publisher.publish(msg) -def main(args=None): +def main(args: list[str] | None = None) -> None: rclpy.init(args=args) node = TurtleRobotControlNode() rclpy.spin(node) diff --git a/robotics/robot-operating-system/src/turtle_robot_launch/launch/turtle_robot.launch.py b/robotics/robot-operating-system/src/turtle_robot_launch/launch/turtle_robot.launch.py index 91d0ad3fe5..215d081f1d 100644 --- a/robotics/robot-operating-system/src/turtle_robot_launch/launch/turtle_robot.launch.py +++ b/robotics/robot-operating-system/src/turtle_robot_launch/launch/turtle_robot.launch.py @@ -5,7 +5,7 @@ from launch_ros.actions import Node -def generate_launch_description(): +def generate_launch_description() -> LaunchDescription: hm_namespace = "hm" turtlesim_node = Node( diff --git a/system-tools/ouch/Makefile b/system-tools/ouch/Makefile index 640177e844..3302067e5b 100644 --- a/system-tools/ouch/Makefile +++ b/system-tools/ouch/Makefile @@ -1,4 +1,4 @@ ouch-compress: ouch compress /path/to/folder folder.tar.zst ouch-decompress: - ouch decompress folder.tar.zst + ouch decompress folder.tar.zst --dir=/tmp/ --quiet