Skip to content

mypy 1.20.0 fixes [ml]#46139

Open
PratibhaShrivastav18 wants to merge 2 commits intoAzure:mainfrom
PratibhaShrivastav18:shrivastavp/fix-mypy
Open

mypy 1.20.0 fixes [ml]#46139
PratibhaShrivastav18 wants to merge 2 commits intoAzure:mainfrom
PratibhaShrivastav18:shrivastavp/fix-mypy

Conversation

@PratibhaShrivastav18
Copy link
Copy Markdown
Member

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates azure-ai-ml to address new mypy 1.20.0 type-checking failures by applying targeted typing workarounds and adjusting internal guidance for fixing mypy issues.

Changes:

  • Expanded a # type: ignore on get_model_artifacts() tuple-unpacking to suppress a new mypy str-unpack error.
  • Added cast(Dict[str, Any], ...) at get_storage_client(**datastore_info) call sites to satisfy mypy’s **kwargs typing.
  • Updated the internal “fix-mypy” skill doc to emphasize fixing only CI-blocking mypy errors and removed PR-creation instructions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
sdk/ml/azure-ai-ml/azure/ai/ml/operations/_local_deployment_helper.py Suppresses new mypy unpacking error with an additional ignore code.
sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_artifact_utilities.py Uses casts / getattr to satisfy mypy typing around datastore info and artifact paths.
.github/skills/ml/fix-mypy/SKILL.md Tightens scope guidance to focus on CI-blocking mypy issues; reorganizes steps.

model_operations: ModelOperations,
download_path: str,
) -> Union[str, Tuple]:
) -> Tuple:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it not break the flow because we are removing one type from it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all code paths actually return a tuple, so it will not be a breaking change.

credential=None,
**kwargs,
) -> Dict[Literal["storage_type", "storage_account", "account_url", "container_name", "credential"], str]:
) -> Dict[str, Any]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we replacing all literal with Any?
Instead of literal shoudn't be enum?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root cause of the mypy error was a type mismatch between the return annotation and the local variable. The return type declared [Dict[Literal[...], str]] but the local variable was typed as bare Dict (which mypy infers as Dict[Any, Any]). At call sites like download_artifact where datastore_info is an Optional[Dict] parameter that gets reassigned from get_datastore_info(), mypy sees a union of [Dict[Any, Any] | Dict[Literal[...], str]] — and mypy 1.20.0 rejects ** unpacking on a union of dict types.

To keep Literal keys, we'd also need to update the parameter types at all call sites (Optional[Dict][Optional[Dict[Literal[...], Any]]], which is verbose and fragile, and requires refactoring at 10+ places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants