From b52b61c883bc3d3368b732f4877c01213f20398c Mon Sep 17 00:00:00 2001 From: Pratibha Shrivastav <164305667+PratibhaShrivastav18@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:43:31 +0530 Subject: [PATCH] remove pylint disable (#38979) --- .../azure/ai/ml/_internal/entities/component.py | 2 +- sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py | 8 ++++---- .../ai/ml/entities/_component/_additional_includes.py | 10 +++++----- .../azure/ai/ml/entities/_component/code.py | 3 +++ .../azure/ai/ml/entities/_component/flow.py | 3 +++ .../ai/ml/entities/_job/sweep/parameterized_sweep.py | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py b/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py index fe3799c761db..1040a12526a0 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py @@ -328,7 +328,7 @@ def _try_build_local_code(self) -> Iterable[Code]: tmp_code_dir: Path # origin code value of internal component will never be None. check _get_origin_code_value for details - with self._generate_additional_includes_obj().merge_local_code_and_additional_includes() as tmp_code_dir: # pylint:disable=contextmanager-generator-missing-cleanup + with self._generate_additional_includes_obj().merge_local_code_and_additional_includes() as tmp_code_dir: # use absolute path in case temp folder & work dir are in different drive tmp_code_dir = tmp_code_dir.absolute() diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py b/sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py index a6842441c853..00e3e24f0034 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py @@ -18,7 +18,7 @@ import os import uuid from datetime import datetime -from typing import Any, Dict, Tuple +from typing import Dict, Tuple from uuid import uuid4 from marshmallow import ValidationError @@ -153,12 +153,12 @@ def error_preprocess(activityLogger, exception): @contextlib.contextmanager -def log_activity( # pylint:disable=useless-return +def log_activity( logger, activity_name, activity_type=ActivityType.INTERNALCALL, custom_dimensions=None, -) -> Any: +): """Log an activity. An activity is a logical block of code that consumers want to monitor. @@ -248,7 +248,7 @@ def log_activity( # pylint:disable=useless-return else: activityLogger.info(message) except Exception: # pylint: disable=W0718 - return # pylint: disable=lost-exception,return-in-finally + pass # pylint: disable-next=docstring-missing-rtype diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/_additional_includes.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/_additional_includes.py index f7fbb98394dd..85f609cac960 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/_additional_includes.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/_additional_includes.py @@ -473,12 +473,12 @@ def merge_local_code_and_additional_includes(self) -> Generator: ) else: raise ValueError(f"Unable to find additional include {additional_include_local_path}.") + try: + yield tmp_folder_path.absolute() - yield tmp_folder_path.absolute() - - # clean up tmp folder as it can be very disk space consuming - shutil.rmtree(tmp_folder_path, ignore_errors=True) - return + finally: + # clean up tmp folder as it can be very disk space consuming + shutil.rmtree(tmp_folder_path, ignore_errors=True) class AdditionalIncludesMixin(ComponentCodeMixin): diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/code.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/code.py index 9fffc19b077b..1f838bec31b6 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/code.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/code.py @@ -259,6 +259,9 @@ def _build_code(self) -> Generator: yield Code(path=origin_code_value) elif code_type in [CodeType.LOCAL, CodeType.NONE]: code: Any + # false-positive by pylint, hence disable it + # (https://github.com/pylint-dev/pylint/blob/main/doc/data/messages + # /c/contextmanager-generator-missing-cleanup/details.rst) with self._try_build_local_code() as code: # pylint:disable=contextmanager-generator-missing-cleanup yield code else: diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/flow.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/flow.py index 822b9de2b867..e4ff06cc5319 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/flow.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/flow.py @@ -530,6 +530,9 @@ def _fill_back_code_value(self, value: str) -> None: @contextlib.contextmanager def _try_build_local_code(self) -> Generator: + # false-positive by pylint, hence disable it + # (https://github.com/pylint-dev/pylint/blob/main/doc/data/messages + # /c/contextmanager-generator-missing-cleanup/details.rst) with super()._try_build_local_code() as code: # pylint:disable=contextmanager-generator-missing-cleanup if not code or not code.path: yield code diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/parameterized_sweep.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/parameterized_sweep.py index e4aaf9c071d0..df33f7c96554 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/parameterized_sweep.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/parameterized_sweep.py @@ -205,6 +205,7 @@ def set_limits( :keyword trial_timeout: timeout in seconds for each trial :paramtype trial_timeout: int """ + # Looks related to https://github.com/pylint-dev/pylint/issues/3502, still an open issue # pylint:disable=attribute-defined-outside-init if self._limits is None: self._limits = SweepJobLimits(