From 87e0bf51f95f7364c43447501b7109f212a27515 Mon Sep 17 00:00:00 2001 From: Jayesh Tanna Date: Thu, 2 Apr 2026 15:44:56 +0530 Subject: [PATCH 1/3] Resolving next-pylint 4.0.5 issues for azure-ai-ml sdk and updating skill.md file --- .github/skills/ml/fix-pylint/SKILL.md | 91 ++----------------- .../entities/_autogen_entities/_model_base.py | 2 +- .../_deployment_template_operations.py | 80 +++++++--------- .../e2etests/test_batch_endpoint.py | 4 +- .../connection/e2etests/test_connections.py | 2 +- .../unittests/test_connection_entity.py | 56 ++++++------ .../e2etests/test_local_endpoint.py | 2 +- .../unittests/test_schedule_entity.py | 6 +- .../unittests/test_sweep_job_schema.py | 6 +- .../unittests/test_hub_entity.py | 2 +- .../unittests/test_project_entity.py | 2 +- 11 files changed, 84 insertions(+), 169 deletions(-) diff --git a/.github/skills/ml/fix-pylint/SKILL.md b/.github/skills/ml/fix-pylint/SKILL.md index 0e0b9f2ebc21..ef2027e41a54 100644 --- a/.github/skills/ml/fix-pylint/SKILL.md +++ b/.github/skills/ml/fix-pylint/SKILL.md @@ -7,6 +7,8 @@ description: Automatically fix pylint issues in azure-ai-ml package following Az This skill automatically fixes pylint warnings in the azure-ai-ml package by analyzing existing code patterns and applying fixes with 100% confidence based on GitHub issues. +> **Scope:** Fix **only mandatory/blocking issues** — warnings that will cause CI to fail. Leave optional/informational warnings as-is. + ## Overview Intelligently fixes pylint issues by: @@ -19,12 +21,11 @@ Intelligently fixes pylint issues by: 7. Searching codebase for existing patterns to follow 8. Applying fixes only with 100% confidence 9. Re-running pylint to verify fixes -10. Creating a pull request that references the GitHub issue -11. Providing a summary of what was fixed +10. Providing a summary of what was fixed ## Running Pylint -**Command for entire package:** +**Command for entire package (tox):** ```powershell cd sdk/ml/azure-ai-ml tox -e pylint --c ../../../eng/tox/tox.ini --root . @@ -146,6 +147,8 @@ Use the existing code patterns to ensure consistency. ### Step 7: Apply Fixes (ONLY if 100% confident) +> **Fix only mandatory/blocking issues.** Skip optional or informational warnings that do not cause CI failure. + **ALLOWED ACTIONS:** Fix warnings with 100% confidence Use existing file patterns as reference @@ -161,14 +164,14 @@ Use the existing code patterns to ensure consistency. Change code style without clear reason Delete code without clear justification -### Step 7: Verify Fixes +### Step 8: Verify Fixes Re-run pylint to ensure: - The warning is resolved - No new warnings were introduced - The code still functions correctly -### Step 8: Summary +### Step 9: Summary Provide a summary: - GitHub issue being addressed @@ -177,67 +180,6 @@ Provide a summary: - Types of fixes applied - Any warnings that need manual review -### Step 9: Create Pull Request - -After successfully fixing pylint issues, create a pull request: - -**Stage and commit the changes:** -```powershell -# Stage all modified files -git add . - -# Create a descriptive commit message referencing the issue -git commit -m "fix(azure-ai-ml): resolve pylint warnings (#) - -- Fixed -- Updated -- All pylint checks now pass - -Closes #" -``` - -**Create pull request using GitHub CLI or MCP server:** - -Option 1 - Using GitHub CLI (if available): -```powershell -# Create a new branch -$branchName = "fix/azure-ai-ml-pylint-" -git checkout -b $branchName - -# Push the branch -git push origin $branchName - -# Create PR using gh CLI -gh pr create ` - --title "fix(azure-ai-ml): Resolve pylint warnings (#)" ` - --body "## Description -This PR fixes pylint warnings in the azure-ai-ml package as reported in #. - -## Changes -- Fixed pylint warnings following Azure SDK Python guidelines -- Ensured consistency with existing code patterns -- Targeted fixes for: -- All pylint checks now pass for the affected areas - -## Testing -- [x] Ran pylint on affected files and verified all warnings are resolved -- [x] No new warnings introduced -- [x] Verified fixes follow existing code patterns - -## Related Issues -Fixes #" ` - --base main ` - --repo Azure/azure-sdk-for-python -``` - -Option 2 - Manual PR creation (if GitHub CLI not available): -1. Push branch: `git push origin ` -2. Navigate to: https://github.com/Azure/azure-sdk-for-python/compare/main... -3. Create the pull request manually with the description above - -Option 3 - Using GitHub MCP server (if available): -Use the GitHub MCP tools to create a pull request programmatically against the Azure/azure-sdk-for-python repository, main branch. - ## Common Pylint Issues and Fixes ### Missing Docstrings @@ -302,7 +244,7 @@ tox -e pylint --c ../../../eng/tox/tox.ini --root . -- $targetFile # Cross-reference with GitHub issue #12345 # 5. Search for existing patterns in codebase -grep -r "similar_pattern" azure/ai/ml/ +Get-ChildItem -Recurse azure/ai/ml/ | Select-String "similar_pattern" # 6. Apply fixes to identified files @@ -310,20 +252,6 @@ grep -r "similar_pattern" azure/ai/ml/ tox -e pylint --c ../../../eng/tox/tox.ini --root . -- $targetFile # 8. Report results - -# 9. Create PR referencing the issue -$branchName = "fix/azure-ai-ml-pylint-12345" -git checkout -b $branchName -git add . -git commit -m "fix(azure-ai-ml): resolve pylint warnings (#12345) - -Closes #12345" -git push origin $branchName -gh pr create ` - --title "fix(azure-ai-ml): Resolve pylint warnings (#12345)" ` - --body "Fixes #12345" ` - --base main ` - --repo Azure/azure-sdk-for-python ``` ## Notes @@ -333,4 +261,3 @@ gh pr create ` - If unsure about a fix, mark it for manual review - Some warnings may require architectural changes - don't force fixes - Test the code after fixing to ensure functionality is preserved -- Always reference the GitHub issue in commits and PRs diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py index 0bd5b20fef3d..1fa68acb1cf4 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py @@ -4,7 +4,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -# pylint: disable=protected-access, broad-except, no-member +# pylint: disable=protected-access, broad-except, no-member, unidiomatic-typecheck import base64 import calendar diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_deployment_template_operations.py b/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_deployment_template_operations.py index 583eb07ac578..97cfe801199a 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_deployment_template_operations.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_deployment_template_operations.py @@ -91,7 +91,7 @@ def _get_registry_endpoint(self) -> str: return f"https://{region}.api.azureml.ms" except Exception as e: - module_logger.warning("Could not determine registry region dynamically: %s. Using default.", e) + module_logger.debug("Could not determine registry region dynamically: %s. Using default.", e) # Fallback to default region if unable to determine dynamically return f"https://int.experiments.azureml-test.net" @@ -337,7 +337,7 @@ def get(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Deploy ) return DeploymentTemplate._from_rest_object(result) except Exception as e: - module_logger.warning("DeploymentTemplate get operation failed: %s", e) + module_logger.debug("DeploymentTemplate get operation failed: %s", e) raise ResourceNotFoundError(f"DeploymentTemplate {name}:{version} not found") from e @distributed_trace @@ -351,31 +351,27 @@ def create_or_update(self, deployment_template: DeploymentTemplate, **kwargs: An :return: DeploymentTemplate object representing the created or updated resource. :rtype: ~azure.ai.ml.entities.DeploymentTemplate """ - try: - # Ensure we have a DeploymentTemplate object - if not isinstance(deployment_template, DeploymentTemplate): - raise ValueError("deployment_template must be a DeploymentTemplate object") + # Ensure we have a DeploymentTemplate object + if not isinstance(deployment_template, DeploymentTemplate): + raise ValueError("deployment_template must be a DeploymentTemplate object") - if hasattr(self._service_client, "deployment_templates"): - endpoint = self._get_registry_endpoint() + if hasattr(self._service_client, "deployment_templates"): + endpoint = self._get_registry_endpoint() - rest_object = deployment_template._to_rest_object() - self._service_client.deployment_templates.begin_create( - endpoint=endpoint, - subscription_id=self._operation_scope.subscription_id, - resource_group_name=self._operation_scope.resource_group_name, - registry_name=self._operation_scope.registry_name, - name=deployment_template.name, - version=deployment_template.version, - body=rest_object, - **kwargs, - ) - return deployment_template - else: - raise RuntimeError("DeploymentTemplate service not available") - except Exception as e: - module_logger.error("DeploymentTemplate create_or_update operation failed: %s", e) - raise + rest_object = deployment_template._to_rest_object() + self._service_client.deployment_templates.begin_create( + endpoint=endpoint, + subscription_id=self._operation_scope.subscription_id, + resource_group_name=self._operation_scope.resource_group_name, + registry_name=self._operation_scope.registry_name, + name=deployment_template.name, + version=deployment_template.version, + body=rest_object, + **kwargs, + ) + return deployment_template + else: + raise RuntimeError("DeploymentTemplate service not available") @distributed_trace @monitor_with_telemetry_mixin(ops_logger, "DeploymentTemplate.Delete", ActivityType.PUBLICAPI) @@ -407,7 +403,7 @@ def delete(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Non except ResourceNotFoundError: raise except Exception as e: - module_logger.error("DeploymentTemplate delete operation failed: %s", e) + module_logger.debug("DeploymentTemplate delete operation failed: %s", e) raise @distributed_trace @@ -423,18 +419,14 @@ def archive(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De :rtype: ~azure.ai.ml.entities.DeploymentTemplate :raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found. """ - try: - # Get the existing template - template = self.get(name=name, version=version, **kwargs) + # Get the existing template + template = self.get(name=name, version=version, **kwargs) - # Set stage to Archived - template.stage = "Archived" + # Set stage to Archived + template.stage = "Archived" - # Update the template using create_or_update - return self.create_or_update(template, **kwargs) - except Exception as e: - module_logger.error("DeploymentTemplate archive operation failed: %s", e) - raise + # Update the template using create_or_update + return self.create_or_update(template, **kwargs) @distributed_trace @monitor_with_telemetry_mixin(ops_logger, "DeploymentTemplate.Restore", ActivityType.PUBLICAPI) @@ -449,15 +441,11 @@ def restore(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De :rtype: ~azure.ai.ml.entities.DeploymentTemplate :raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found. """ - try: - # Get the existing template - template = self.get(name=name, version=version, **kwargs) + # Get the existing template + template = self.get(name=name, version=version, **kwargs) - # Set stage to Development - template.stage = "Development" + # Set stage to Development + template.stage = "Development" - # Update the template using create_or_update - return self.create_or_update(template, **kwargs) - except Exception as e: - module_logger.error("DeploymentTemplate restore operation failed: %s", e) - raise + # Update the template using create_or_update + return self.create_or_update(template, **kwargs) diff --git a/sdk/ml/azure-ai-ml/tests/batch_services/e2etests/test_batch_endpoint.py b/sdk/ml/azure-ai-ml/tests/batch_services/e2etests/test_batch_endpoint.py index 59889523d6a1..9260586bb452 100644 --- a/sdk/ml/azure-ai-ml/tests/batch_services/e2etests/test_batch_endpoint.py +++ b/sdk/ml/azure-ai-ml/tests/batch_services/e2etests/test_batch_endpoint.py @@ -34,7 +34,7 @@ def test_batch_endpoint_create(self, client: MLClient, rand_batch_name: Callable try: client.batch_endpoints.get(name=name) except Exception as e: - assert type(e) is ResourceNotFoundError + assert isinstance(e, ResourceNotFoundError) return raise Exception(f"Batch endpoint {name} is supposed to be deleted.") @@ -62,7 +62,7 @@ def test_mlflow_batch_endpoint_create_and_update( try: client.batch_endpoints.get(name=name) except Exception as e: - assert type(e) is ResourceNotFoundError + assert isinstance(e, ResourceNotFoundError) return raise Exception(f"Batch endpoint {name} is supposed to be deleted.") diff --git a/sdk/ml/azure-ai-ml/tests/connection/e2etests/test_connections.py b/sdk/ml/azure-ai-ml/tests/connection/e2etests/test_connections.py index a792261c1cc6..97f86d46db64 100644 --- a/sdk/ml/azure-ai-ml/tests/connection/e2etests/test_connections.py +++ b/sdk/ml/azure-ai-ml/tests/connection/e2etests/test_connections.py @@ -256,7 +256,7 @@ def test_workspace_connections_create_update_and_delete_ai_search( wps_connection = client.connections.create_or_update(workspace_connection=wps_connection) client.connections.delete(name=wps_connection_name) - assert type(wps_connection) == AzureAISearchConnection + assert isinstance(wps_connection, AzureAISearchConnection) assert wps_connection.name == wps_connection_name assert wps_connection.credentials.type == camel_to_snake(ConnectionAuthType.API_KEY) # assert wps_connection.api_key == "3333" # TODO add api key retrieval everywhere diff --git a/sdk/ml/azure-ai-ml/tests/connection/unittests/test_connection_entity.py b/sdk/ml/azure-ai-ml/tests/connection/unittests/test_connection_entity.py index f147454aade9..b1ca89f39430 100644 --- a/sdk/ml/azure-ai-ml/tests/connection/unittests/test_connection_entity.py +++ b/sdk/ml/azure-ai-ml/tests/connection/unittests/test_connection_entity.py @@ -55,7 +55,7 @@ def assert_connections_are_similar(self, conn1: WorkspaceConnection, conn2: Work assert conn1 is not None assert conn2 is not None assert conn1.name == conn2.name - assert type(conn1) == type(conn2) + assert type(conn1) == type(conn2) # pylint: disable=unidiomatic-typecheck assert conn1.type == conn2.type assert conn1.target == conn2.target assert conn1.tags == conn2.tags # Check deprecated access @@ -146,7 +146,7 @@ def simple_workspace_connection_validation(ws_connection): def test_blob_storage(self): ws_connection = load_connection(source="./tests/test_configs/connection/blob_store_acc_key.yaml") - assert type(ws_connection) == AzureBlobStoreConnection + assert isinstance(ws_connection, AzureBlobStoreConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_BLOB) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.ACCOUNT_KEY) assert ws_connection.credentials.account_key == "9876" @@ -158,7 +158,7 @@ def test_blob_storage(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/blob_store_sas.yaml") - assert type(ws_connection) == AzureBlobStoreConnection + assert isinstance(ws_connection, AzureBlobStoreConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_BLOB) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.SAS) assert ws_connection.credentials.sas_token == "some_pat" @@ -166,7 +166,7 @@ def test_blob_storage(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/blob_store_entra.yaml") - assert type(ws_connection) == AzureBlobStoreConnection + assert isinstance(ws_connection, AzureBlobStoreConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_BLOB) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.AAD) assert ws_connection.name == "test_ws_conn_blob_store3" @@ -174,7 +174,7 @@ def test_blob_storage(self): def test_alds_gen2(self): ws_connection = load_connection(source="./tests/test_configs/connection/alds_gen2_sp.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == ConnectionTypes.AZURE_DATA_LAKE_GEN_2 assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.SERVICE_PRINCIPAL) assert ws_connection.credentials.tenant_id == "1234" @@ -191,7 +191,7 @@ def test_alds_gen2(self): self.check_rest_conversion_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/alds_gen2_entra.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == ConnectionTypes.AZURE_DATA_LAKE_GEN_2 assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.AAD) assert ws_connection.name == "test_gen2_conn2" @@ -200,7 +200,7 @@ def test_alds_gen2(self): def test_one_lake(self): # Note: also tests SP credential. ws_connection = load_connection(source="./tests/test_configs/connection/one_lake_with_name.yaml") - assert type(ws_connection) == MicrosoftOneLakeConnection + assert isinstance(ws_connection, MicrosoftOneLakeConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_ONE_LAKE) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.SERVICE_PRINCIPAL) assert ws_connection.credentials.tenant_id == "1234" @@ -217,7 +217,7 @@ def test_one_lake(self): # Note: also tests AAD credential ws_connection = load_connection(source="./tests/test_configs/connection/one_lake_with_id.yaml") - assert type(ws_connection) == MicrosoftOneLakeConnection + assert isinstance(ws_connection, MicrosoftOneLakeConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_ONE_LAKE) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.AAD) assert ws_connection.name == "one_lake_with_id" @@ -226,7 +226,7 @@ def test_one_lake(self): def test_azure_open_ai(self): ws_connection = load_connection(source="./tests/test_configs/connection/azure_open_ai_api.yaml") - assert type(ws_connection) == AzureOpenAIConnection + assert isinstance(ws_connection, AzureOpenAIConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_OPEN_AI) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.API_KEY) assert ws_connection.credentials.key == "12344" @@ -240,7 +240,7 @@ def test_azure_open_ai(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/azure_open_ai_entra.yaml") - assert type(ws_connection) == AzureOpenAIConnection + assert isinstance(ws_connection, AzureOpenAIConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.AZURE_OPEN_AI) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.AAD) assert ws_connection.name == "azure_open_ai_conn_entra" @@ -253,7 +253,7 @@ def test_azure_open_ai(self): def test_ai_services(self): ws_connection = load_connection(source="./tests/test_configs/connection/ai_services_with_key.yaml") - assert type(ws_connection) == AzureAIServicesConnection + assert isinstance(ws_connection, AzureAIServicesConnection) assert ws_connection.type == ConnectionTypes.AZURE_AI_SERVICES assert ws_connection.api_key == "2222" assert ws_connection.name == "ai_services_conn_api" @@ -262,7 +262,7 @@ def test_ai_services(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/ai_services_with_entra.yaml") - assert type(ws_connection) == AzureAIServicesConnection + assert isinstance(ws_connection, AzureAIServicesConnection) assert ws_connection.type == ConnectionTypes.AZURE_AI_SERVICES assert ws_connection.name == "ai_services_conn_entra" assert ws_connection.target == "my_endpoint" @@ -272,7 +272,7 @@ def test_ai_services(self): def test_content_safety(self): ws_connection = load_connection(source="./tests/test_configs/connection/content_safety_with_key.yaml") - assert type(ws_connection) == AzureContentSafetyConnection + assert isinstance(ws_connection, AzureContentSafetyConnection) assert ws_connection.type == ConnectionTypes.AZURE_CONTENT_SAFETY assert ws_connection.metadata["Kind"] == CognitiveServiceKinds.CONTENT_SAFETY assert ws_connection.api_key == "2222" @@ -281,7 +281,7 @@ def test_content_safety(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/content_safety_with_entra.yaml") - assert type(ws_connection) == AzureContentSafetyConnection + assert isinstance(ws_connection, AzureContentSafetyConnection) assert ws_connection.type == ConnectionTypes.AZURE_CONTENT_SAFETY assert ws_connection.metadata["Kind"] == CognitiveServiceKinds.CONTENT_SAFETY assert ws_connection.name == "content_safety_conn_entra" @@ -292,7 +292,7 @@ def test_content_safety(self): def test_speech(self): ws_connection = load_connection(source="./tests/test_configs/connection/speech_with_key.yaml") - assert type(ws_connection) == AzureSpeechServicesConnection + assert isinstance(ws_connection, AzureSpeechServicesConnection) assert ws_connection.type == ConnectionTypes.AZURE_SPEECH_SERVICES assert ws_connection.metadata["Kind"] == CognitiveServiceKinds.SPEECH assert ws_connection.api_key == "2222" @@ -301,7 +301,7 @@ def test_speech(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/speech_with_entra.yaml") - assert type(ws_connection) == AzureSpeechServicesConnection + assert isinstance(ws_connection, AzureSpeechServicesConnection) assert ws_connection.type == ConnectionTypes.AZURE_SPEECH_SERVICES assert ws_connection.metadata["Kind"] == CognitiveServiceKinds.SPEECH assert ws_connection.name == "speech_entra" @@ -311,7 +311,7 @@ def test_speech(self): def test_search(self): ws_connection = load_connection(source="./tests/test_configs/connection/search_with_key.yaml") - assert type(ws_connection) == AzureAISearchConnection + assert isinstance(ws_connection, AzureAISearchConnection) assert ws_connection.type == ConnectionTypes.AZURE_SEARCH assert ws_connection.api_key == "3333" assert ws_connection.name == "search_api" @@ -319,7 +319,7 @@ def test_search(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/search_with_entra.yaml") - assert type(ws_connection) == AzureAISearchConnection + assert isinstance(ws_connection, AzureAISearchConnection) assert ws_connection.type == ConnectionTypes.AZURE_SEARCH assert ws_connection.name == "search_entra" assert ws_connection.target == "this_is_a_target_too" @@ -328,7 +328,7 @@ def test_search(self): def test_api_key(self): ws_connection = load_connection(source="./tests/test_configs/connection/api_key_conn.yaml") - assert type(ws_connection) == APIKeyConnection + assert isinstance(ws_connection, APIKeyConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.API_KEY) assert ws_connection.api_key == "3232" assert ws_connection.name == "just_api" @@ -337,7 +337,7 @@ def test_api_key(self): def test_custom(self): ws_connection = load_connection(source="./tests/test_configs/connection/custom.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionTypes.CUSTOM) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.API_KEY) assert ws_connection.credentials.key == "4444" @@ -348,7 +348,7 @@ def test_custom(self): def test_open_ai(self): ws_connection = load_connection(source="./tests/test_configs/connection/not_azure_open_ai.yaml") - assert type(ws_connection) == OpenAIConnection + assert isinstance(ws_connection, OpenAIConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.OPEN_AI) assert ws_connection.api_key == "123446" assert ws_connection.name == "open_ai_conn" @@ -357,7 +357,7 @@ def test_open_ai(self): def test_serp(self): ws_connection = load_connection(source="./tests/test_configs/connection/serp.yaml") - assert type(ws_connection) == SerpConnection + assert isinstance(ws_connection, SerpConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.SERP) assert ws_connection.api_key == "1234467" assert ws_connection.name == "serp_conn" @@ -367,7 +367,7 @@ def test_serp(self): def test_git(self): ws_connection = load_connection(source="./tests/test_configs/connection/git_pat.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.GIT) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.PAT) assert ws_connection.credentials.pat == "dummy_pat" @@ -376,7 +376,7 @@ def test_git(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/git_no_cred.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.GIT) assert ws_connection.credentials.type == ConnectionAuthType.NONE assert ws_connection.name == "git_no_cred_conn" @@ -385,7 +385,7 @@ def test_git(self): def test_python_feed(self): ws_connection = load_connection(source="./tests/test_configs/connection/python_feed_pat.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.PYTHON_FEED) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.PAT) assert ws_connection.credentials.pat == "dummy_pat" @@ -394,7 +394,7 @@ def test_python_feed(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/python_feed_user_pass.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.PYTHON_FEED) assert ws_connection.credentials.type == camel_to_snake(ConnectionAuthType.USERNAME_PASSWORD) assert ws_connection.credentials.username == "john" @@ -404,7 +404,7 @@ def test_python_feed(self): self.check_all_conversions_stable(ws_connection) ws_connection = load_connection(source="./tests/test_configs/connection/python_feed_no_cred.yaml") - assert type(ws_connection) == WorkspaceConnection + assert isinstance(ws_connection, WorkspaceConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.PYTHON_FEED) assert ws_connection.credentials.type == ConnectionAuthType.NONE assert ws_connection.name == "test_ws_conn_python_no_cred" @@ -435,7 +435,7 @@ def test_container_registry(self): def test_serverless(self): ws_connection = load_connection(source="./tests/test_configs/connection/serverless_api.yaml") - assert type(ws_connection) == ServerlessConnection + assert isinstance(ws_connection, ServerlessConnection) assert ws_connection.type == camel_to_snake(ConnectionCategory.SERVERLESS) assert ws_connection.api_key == "1029" assert ws_connection.name == "serverless_with_api" diff --git a/sdk/ml/azure-ai-ml/tests/local_endpoint/e2etests/test_local_endpoint.py b/sdk/ml/azure-ai-ml/tests/local_endpoint/e2etests/test_local_endpoint.py index 10f672287bc6..a7f804ab4d87 100644 --- a/sdk/ml/azure-ai-ml/tests/local_endpoint/e2etests/test_local_endpoint.py +++ b/sdk/ml/azure-ai-ml/tests/local_endpoint/e2etests/test_local_endpoint.py @@ -298,7 +298,7 @@ def run_local_endpoint_tests_e2e_create( assert get_obj.scoring_uri != "" data = client.online_endpoints.invoke(endpoint_name=endpoint_name, request_file=request_file, local=True) - assert type(data) is str + assert isinstance(data, str) if is_sklearn: assert "5215" in data assert "3726" in data diff --git a/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_entity.py b/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_entity.py index 1e8bfa50f24b..a4ea794ace51 100644 --- a/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_entity.py +++ b/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_entity.py @@ -19,9 +19,9 @@ def test_load_cron_schedule_with_file_reference(self): test_path = "./tests/test_configs/schedule/hello_cron_schedule_with_file_reference.yml" def simple_schedule_validation(schedule): - assert type(schedule) == JobSchedule - assert type(schedule.create_job) == PipelineJob - assert type(schedule.trigger) == CronTrigger + assert isinstance(schedule, JobSchedule) + assert isinstance(schedule.create_job, PipelineJob) + assert isinstance(schedule.trigger, CronTrigger) schedule = verify_entity_load_and_dump(load_schedule, simple_schedule_validation, test_path)[0] schedule.properties["test"] = "val" diff --git a/sdk/ml/azure-ai-ml/tests/sweep_job/unittests/test_sweep_job_schema.py b/sdk/ml/azure-ai-ml/tests/sweep_job/unittests/test_sweep_job_schema.py index deb2b9e1e6de..b2fa04ff2a85 100644 --- a/sdk/ml/azure-ai-ml/tests/sweep_job/unittests/test_sweep_job_schema.py +++ b/sdk/ml/azure-ai-ml/tests/sweep_job/unittests/test_sweep_job_schema.py @@ -190,7 +190,7 @@ def test_sweep_with_ints(self): assert rest.properties.search_space["ss"] == expected_rest assert vars(sweep.search_space["ss"]) == expected_ss for var in rest.properties.search_space["ss"][1]: - assert type(var) == int + assert isinstance(var, int) def test_sweep_with_floats(self): expected_rest = ["quniform", [1.1, 100.12, 1]] @@ -215,7 +215,7 @@ def test_sweep_with_floats(self): assert vars(sweep.search_space["ss"]) == expected_ss # Ensure that min_value and max_value are floats, ignoring q for var in rest.properties.search_space["ss"][1][:2]: - assert type(var) == float + assert isinstance(var, float) def test_sweep_with_string(self): expected_rest = ["choice", [["gbdt", "dart"]]] @@ -310,7 +310,7 @@ def test_sweep_with_dicts(self): assert vars(sweep.search_space["ss"]) == expected_ss # Ensure that all elements of values are dicts for var in rest.properties.search_space["ss"][1][0]: - assert type(var) == dict + assert isinstance(var, dict) def test_sweep_termination_roundtrip(self): paths = [ diff --git a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_hub_entity.py b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_hub_entity.py index 283c43f41b81..12bd1d4ac1b0 100644 --- a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_hub_entity.py +++ b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_hub_entity.py @@ -10,7 +10,7 @@ class TestProjectEntity: def test_project_schema_manipulation(self) -> None: hub = load_workspace(source="./tests/test_configs/workspace/ai_workspaces/aihub_min.yml") assert hub is not None - assert type(hub) == Hub + assert isinstance(hub, Hub) assert hub.name == "hub_name" assert hub.location == "WestCentralUS" assert ( diff --git a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_project_entity.py b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_project_entity.py index 4ffe7a2682bc..43fbd57bff85 100644 --- a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_project_entity.py +++ b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_project_entity.py @@ -11,7 +11,7 @@ def test_project_schema_manipulation(self) -> None: project = load_workspace(source="./tests/test_configs/workspace/ai_workspaces/test_project.yml") assert project is not None - assert type(project) == Project + assert isinstance(project, Project) assert project.name == "test_project" assert project.description == "A test project for unit tests" assert ( From 1f20ddac2ea99b0b7e6bf67751f68d0fcb41743c Mon Sep 17 00:00:00 2001 From: Jayesh Tanna Date: Thu, 2 Apr 2026 16:51:11 +0530 Subject: [PATCH 2/3] solving review comment --- .../azure/ai/ml/entities/_autogen_entities/_model_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py index 1fa68acb1cf4..74e6642dce23 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py @@ -4,7 +4,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -# pylint: disable=protected-access, broad-except, no-member, unidiomatic-typecheck +# pylint: disable=protected-access, broad-except, no-member import base64 import calendar @@ -683,9 +683,9 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911 # is it optional? try: - if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore + if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore # pylint: disable=unidiomatic-typecheck if_obj_deserializer = _get_deserialize_callable_from_annotation( - next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore + next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore # pylint: disable=unidiomatic-typecheck ) return functools.partial(_deserialize_with_optional, if_obj_deserializer) From f81cdcf5aa1990c0ca7c6ae3d9f0131a46962cf7 Mon Sep 17 00:00:00 2001 From: Jayesh Tanna Date: Thu, 2 Apr 2026 18:14:16 +0530 Subject: [PATCH 3/3] applying black formatter --- .../azure/ai/ml/entities/_autogen_entities/_model_base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py index 74e6642dce23..3b78408e96ed 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/_model_base.py @@ -683,9 +683,13 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911 # is it optional? try: - if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore # pylint: disable=unidiomatic-typecheck + if any( + a for a in annotation.__args__ if a == type(None) + ): # pyright: ignore # pylint: disable=unidiomatic-typecheck if_obj_deserializer = _get_deserialize_callable_from_annotation( - next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore # pylint: disable=unidiomatic-typecheck + next(a for a in annotation.__args__ if a != type(None)), + module, + rf, # pyright: ignore # pylint: disable=unidiomatic-typecheck ) return functools.partial(_deserialize_with_optional, if_obj_deserializer)