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

Get successful mypy pass on azure core #5466

Merged
merged 14 commits into from
May 25, 2019
Merged

Conversation

rakshith91
Copy link
Contributor

Duplicate of #5266

Resolves #5022

@rakshith91 rakshith91 requested a review from lmazuel as a code owner May 24, 2019 01:22
@adxsdk6
Copy link

adxsdk6 commented May 24, 2019

Can one of the admins verify this patch?

@rakshith91 rakshith91 requested a review from bryevdv May 24, 2019 17:40
@rakshith91 rakshith91 self-assigned this May 24, 2019
# --------------------------------------------------------------------------
from typing import List, Union, Optional, TypeVar, Callable
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy
from azure.core.exceptions import (
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Is sender any?

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

@xiangyan99 xiangyan99 May 24, 2019

Choose a reason for hiding this comment

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

  1. transport is one kind of transport type, not any
  2. Shouldn't List[Union[HTTPPolicy, SansIOHTTPPolicy] be PoliciesType?

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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")
Copy link
Member

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

Copy link
Member

@xiangyan99 xiangyan99 May 24, 2019

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")
Copy link
Member

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]:
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

PipelineRequestType?

@rakshith91 rakshith91 merged commit 76e055c into Azure:master May 25, 2019
@rakshith91 rakshith91 deleted the mypy-core branch May 25, 2019 01:44
azure-sdk added a commit that referenced this pull request Feb 21, 2023
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.

[azure-core]Need successful MyPy pass
3 participants