-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Get successful mypy pass on azure core #5466
Conversation
Can one of the admins verify this patch? |
# -------------------------------------------------------------------------- | ||
from typing import List, Union, Optional, TypeVar, Callable | ||
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy | ||
from azure.core.exceptions import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need "try" for AsyncHTTPPolicy?
@@ -60,7 +60,7 @@ def send(self, request): | |||
class _TransportRunner(HTTPPolicy): | |||
|
|||
def __init__(self, sender): | |||
# type: (HttpTransport) -> None | |||
# type: (Any) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is sender any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had HTTPSender in msrest which we don't have anymore. Can't find a relevant sender class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think HttpTransport is correct
@@ -80,7 +80,7 @@ class Pipeline(AbstractContextManager, Generic[HTTPRequestType, HTTPResponseType | |||
""" | |||
|
|||
def __init__(self, transport, policies=None): | |||
# type: (HttpTransport, List[Union[HTTPPolicy, SansIOHTTPPolicy]]) -> None | |||
# type: (Any, List[Union[HTTPPolicy, SansIOHTTPPolicy]]) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- transport is one kind of transport type, not any
- Shouldn't List[Union[HTTPPolicy, SansIOHTTPPolicy] be PoliciesType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included this
@@ -204,15 +206,15 @@ class ContentDecodePolicy(SansIOHTTPPolicy): | |||
|
|||
@classmethod | |||
def deserialize_from_text(cls, response, content_type=None): | |||
# type: (Optional[Union[AnyStr, IO]], Optional[str]) -> Any | |||
# type: (Optional[PipelineResponse], Optional[str]) -> Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we missed cls and response is not optional
@@ -260,16 +262,16 @@ def _json_attemp(data): | |||
|
|||
@classmethod | |||
def deserialize_from_http_generics(cls, response): | |||
# type: (Optional[Union[AnyStr, IO]], Mapping) -> Any | |||
# type: (PipelineResponse) -> Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, cls?
@@ -127,7 +129,7 @@ class RequestsTransport(HttpTransport): | |||
_protocols = ['http://', 'https://'] | |||
|
|||
def __init__(self, configuration=None, session=None, session_owner=True): | |||
# type: (Optional[requests.Session]) -> None | |||
# type: (Optional[Any], Optional[requests.Session], Any) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session_owner is bool
from msrest.serialization import Model # type: ignore # pylint: disable=unused-import | ||
|
||
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType") | ||
HTTPRequestType = TypeVar("HTTPRequestType") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTPRequestType is already defined in sdk/core/azure-core/azure/core/pipeline/init.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And seems like the only one uses AsyncHTTPResponseType & ImplPoliciesType is base_async.py
@@ -29,6 +29,7 @@ | |||
|
|||
from azure.core.pipeline import PipelineRequest, PipelineResponse, PipelineContext | |||
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy | |||
from azure.core.common import ImplPoliciesType, PoliciesType | |||
|
|||
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsyncHTTPResponseType is already defined in azure.core.common
@@ -102,7 +102,7 @@ def _get_request_data(self, request): #pylint: disable=no-self-use | |||
return form_data | |||
return request.data | |||
|
|||
async def send(self, request: HttpRequest, **config: Any) -> AsyncHttpResponse: | |||
async def send(self, request: HttpRequest, **config: Any) -> Optional[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not AsyncHttpResponse?
@@ -43,21 +43,22 @@ | |||
# If one day we reach the point where "requests" can be skip totally, | |||
# might provide our own implementation | |||
from requests.structures import CaseInsensitiveDict | |||
from azure.core.pipeline import ABC, AbstractContextManager | |||
from azure.core.pipeline import ABC, AbstractContextManager, PipelineRequest, PipelineResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use PipelineRequestType instead of import?
Can this change pass PyLint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it does.
@@ -127,7 +129,7 @@ class RequestsTransport(HttpTransport): | |||
_protocols = ['http://', 'https://'] | |||
|
|||
def __init__(self, configuration=None, session=None, session_owner=True): | |||
# type: (Optional[requests.Session]) -> None | |||
# type: (Optional[Any], Optional[requests.Session], bool) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is configuration type, not any
@@ -31,23 +31,23 @@ | |||
from typing import (TYPE_CHECKING, Generic, TypeVar, cast, IO, List, Union, Any, Mapping, Dict, Optional, # pylint: disable=unused-import | |||
Tuple, Callable, Iterator) | |||
|
|||
from azure.core.pipeline import ABC | |||
from azure.core.pipeline import ABC, PipelineRequest, PipelineResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use PipelineRequestType
@@ -98,7 +98,7 @@ class RequestHistory(object): | |||
""" | |||
|
|||
def __init__(self, http_request, http_response=None, error=None, context=None): | |||
# type: (PipelineRequest[HTTPRequestType], Exception, Optional[Dict[str, Any]]) -> None | |||
# type: (PipelineRequest, PipelineResponse, Exception, Optional[Dict[str, Any]]) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional[PipelineResponse]
@@ -26,6 +26,7 @@ | |||
""" | |||
This module is the requests implementation of Pipeline ABC | |||
""" | |||
from azure.core.pipeline import PipelineRequest, PipelineResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PipelineRequestType?
…5456 (#28923) Co-authored-by: Mike Harder <[email protected]>
Duplicate of #5266
Resolves #5022