Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions autorest/codegen/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def imports(code_model, async_mode: bool) -> FileImport:
file_import.add_from_import("msrest", "Deserializer", ImportType.AZURECORE)
file_import.add_from_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)

# if code_model.options["credential"]:
# file_import.add_from_import("azure.core.credentials", "TokenCredential", ImportType.AZURECORE)
any_optional_gp = any(not gp.required for gp in code_model.global_parameters)

if any_optional_gp or code_model.base_url:
Expand All @@ -43,4 +41,10 @@ def imports(code_model, async_mode: bool) -> FileImport:
file_import.add_from_import(
"azure.core", Client.pipeline_class(code_model, async_mode), ImportType.AZURECORE
)

if not code_model.sorted_schemas:
# in this case, we have client_models = {} in the service client, which needs a type annotation
# this import will always be commented, so will always add it to the typing section
file_import.add_from_import("typing", "Dict", ImportType.STDLIB, TypingSection.TYPING)

return file_import
2 changes: 1 addition & 1 deletion autorest/codegen/templates/service_client.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class {{ code_model.class_name }}({{ base_class }}):
{% if code_model.sorted_schemas %}
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
{% else %}
client_models = {}
client_models = {} # type: Dict[str, Any]
{% endif %}
self._serialize = Serializer(client_models)
{% if not code_model.options['client_side_validation'] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional
from typing import Any, Dict, Optional

from azure.core.credentials import TokenCredential

Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(
self._config = AutoRestHeadTestServiceConfiguration(credential, **kwargs)
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Dict

from azure.core.credentials_async import AsyncTokenCredential

from ._configuration_async import AutoRestHeadTestServiceConfiguration
Expand Down Expand Up @@ -41,7 +43,7 @@ def __init__(
self._config = AutoRestHeadTestServiceConfiguration(credential, **kwargs)
self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional
from typing import Any, Dict, Optional

from azure.core.credentials import TokenCredential

Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(
self._config = AutoRestHeadExceptionTestServiceConfiguration(credential, **kwargs)
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Dict

from azure.core.credentials_async import AsyncTokenCredential

from ._configuration_async import AutoRestHeadExceptionTestServiceConfiguration
Expand Down Expand Up @@ -41,7 +43,7 @@ def __init__(
self._config = AutoRestHeadExceptionTestServiceConfiguration(credential, **kwargs)
self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional
from typing import Any, Dict, Optional

from ._configuration import NonStringEnumsClientConfiguration
from .operations import IntOperations
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(
self._config = NonStringEnumsClientConfiguration(**kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, Optional
from typing import Any, Optional, TYPE_CHECKING

from azure.core import AsyncPipelineClient
from msrest import Deserializer, Serializer

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Dict

from ._configuration_async import NonStringEnumsClientConfiguration
from .operations_async import IntOperations
from .operations_async import FloatOperations
Expand All @@ -37,7 +41,7 @@ def __init__(
self._config = NonStringEnumsClientConfiguration(**kwargs)
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional
from typing import Any, Dict, Optional

from ._configuration import ObjectTypeClientConfiguration
from .operations import ObjectTypeClientOperationsMixin
Expand All @@ -37,7 +37,7 @@ def __init__(
self._config = ObjectTypeClientConfiguration(**kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, Optional
from typing import Any, Optional, TYPE_CHECKING

from azure.core import AsyncPipelineClient
from msrest import Deserializer, Serializer

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Dict

from ._configuration_async import ObjectTypeClientConfiguration
from .operations_async import ObjectTypeClientOperationsMixin

Expand All @@ -32,7 +36,7 @@ def __init__(
self._config = ObjectTypeClientConfiguration(**kwargs)
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {}
client_models = {} # type: Dict[str, Any]
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

Expand Down