Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[evaluation] ci: Enable mypy #37615

Merged
merged 102 commits into from
Oct 8, 2024
Merged

Conversation

kdestin
Copy link
Member

@kdestin kdestin commented Sep 27, 2024

Description

This pull request enables mypy in CI for azure-ai-evaluation and resolves outstanding type errors

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.

@kdestin kdestin requested a review from a team as a code owner September 27, 2024 19:46
@github-actions github-actions bot added the Evaluation Issues related to the client library for Azure AI Evaluation label Sep 27, 2024
@kdestin kdestin changed the title [evaluation] ci: Enable mypy [DO NOT MERGE][evaluation] ci: Enable mypy Sep 27, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Sep 27, 2024

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-ai-evaluation

@kdestin kdestin force-pushed the evaluation/mypy/enable branch 4 times, most recently from 2e979f9 to 5897e7d Compare October 3, 2024 17:08
@kdestin kdestin changed the title [DO NOT MERGE][evaluation] ci: Enable mypy [evaluation] ci: Enable mypy Oct 3, 2024
… methods

   _http_utils.py extensively uses decorators to implement the
   "convenience" request methods (get, post, put, etc...) for
    {Async}HttpPipeline, since they all share a common underlying
    implementation.

    However neither decorator annotated its return type (the type of the
    decorated function). Initially this was because the accurate type
    couldn't be spelled using a `Callable`, and pylance still did
    a fine job providing intellisense.

    It turns out that it currently isn't possible to spell it
    with a callable typing.Protocol. Our decorator applies to a method,
    and mypy struggles with the removal of the `self` attribute that
    occurs when a method binds to an object (see python/mypy issue
    Azure#16200).

    This commit resolves this by making the implementation of the http
    pipelines more verbose, removing the decorators and unrolling the
    implementation to each convenience method.

    Using `Unpack[TypeDict]` to annotate kwargs makes this substantially
    more readable, but this causes mypy to complain if unknown keys
    are passed as kwargs (useful for request-specific pipeline
    configuration).
…Client,CodeClient]

    Despite having similar interfaces with compatible calling conventions,
    the fact that ProxyClient and CodeClient have different "run" types
    (ProxyRun and CodeRun) causes type errors when dealing with a
    client of type Union[ProxyClient,CodeRun]. Mypy must consider the case
    when the wrong run type is used for a given client, despite that
    not being possible in this function.

    Refactoring the relevant code into a function allows us to clarify
    to mypy that client and run types are used consistently.
         Promptflow does reflection on type annotations, and only
         accepts a dataclass, typeddict, or string as return type
         annotation.
    Promptflow does reflection on type annotations and only allows
    dict
    Promptflow does reflection on param types and disallows TypedDicts
@kdestin kdestin merged commit a852079 into Azure:main Oct 8, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Evaluation Issues related to the client library for Azure AI Evaluation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants