added future annotations
This commit is contained in:
Родитель
000de953de
Коммит
281176a3fa
|
@ -4,7 +4,7 @@ repos:
|
|||
hooks:
|
||||
- id: black
|
||||
language_version: python3
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: 3.9.1 # Use the ref you want to point at
|
||||
hooks:
|
||||
- id: flake8
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# --------------------------------------------------------------------------
|
||||
"""This module contains abstract classes for the various clients of the Azure IoT Hub Device SDK
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
import abc
|
||||
import logging
|
||||
import threading
|
||||
|
@ -238,7 +238,12 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
self._mqtt_pipeline.pipeline_configuration.sastoken = new_token_o
|
||||
|
||||
@abc.abstractmethod
|
||||
def _generic_receive_handler_setter(self, handler_name: str, feature_name: str, new_handler: Optional[FunctionOrCoroutine[[Any], Any]]) -> None:
|
||||
def _generic_receive_handler_setter(
|
||||
self,
|
||||
handler_name: str,
|
||||
feature_name: str,
|
||||
new_handler: Optional[FunctionOrCoroutine[[Any], Any]],
|
||||
) -> None:
|
||||
# Will be implemented differently in child classes, but define here for static analysis
|
||||
pass
|
||||
|
||||
|
@ -315,7 +320,7 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
hostname=connection_string[cs.HOST_NAME],
|
||||
gateway_hostname=connection_string.get(cs.GATEWAY_HOST_NAME),
|
||||
sastoken=sastoken,
|
||||
**config_kwargs
|
||||
**config_kwargs,
|
||||
)
|
||||
if cls.__name__ == "IoTHubDeviceClient":
|
||||
pipeline_configuration.blob_upload = True
|
||||
|
@ -387,7 +392,7 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
module_id=vals["module_id"],
|
||||
hostname=vals["hostname"],
|
||||
sastoken=sastoken_o,
|
||||
**config_kwargs
|
||||
**config_kwargs,
|
||||
)
|
||||
if cls.__name__ == "IoTHubDeviceClient":
|
||||
pipeline_configuration.blob_upload = True # Blob Upload is a feature on Device Clients
|
||||
|
@ -423,7 +428,9 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def send_method_response(self, method_request: MethodRequest, payload: Dict[str, JSONSerializable], status: int) -> None:
|
||||
def send_method_response(
|
||||
self, method_request: MethodRequest, payload: Dict[str, JSONSerializable], status: int
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -522,7 +529,9 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
return self._handler_manager.on_twin_desired_properties_patch_received
|
||||
|
||||
@on_twin_desired_properties_patch_received.setter
|
||||
def on_twin_desired_properties_patch_received(self, value: FunctionOrCoroutine[[TwinPatch], None]):
|
||||
def on_twin_desired_properties_patch_received(
|
||||
self, value: FunctionOrCoroutine[[TwinPatch], None]
|
||||
):
|
||||
self._generic_receive_handler_setter(
|
||||
"on_twin_desired_properties_patch_received", pipeline_constant.TWIN_PATCHES, value
|
||||
)
|
||||
|
@ -530,7 +539,9 @@ class AbstractIoTHubClient(abc.ABC):
|
|||
|
||||
class AbstractIoTHubDeviceClient(AbstractIoTHubClient):
|
||||
@classmethod
|
||||
def create_from_x509_certificate(cls, x509: X509, hostname: str, device_id: str, **kwargs) -> Self:
|
||||
def create_from_x509_certificate(
|
||||
cls, x509: X509, hostname: str, device_id: str, **kwargs
|
||||
) -> Self:
|
||||
"""
|
||||
Instantiate a client using X509 certificate authentication.
|
||||
|
||||
|
@ -592,7 +603,9 @@ class AbstractIoTHubDeviceClient(AbstractIoTHubClient):
|
|||
return cls(mqtt_pipeline, http_pipeline)
|
||||
|
||||
@classmethod
|
||||
def create_from_symmetric_key(cls, symmetric_key: str, hostname: str, device_id: str, **kwargs) -> Self:
|
||||
def create_from_symmetric_key(
|
||||
cls, symmetric_key: str, hostname: str, device_id: str, **kwargs
|
||||
) -> Self:
|
||||
"""
|
||||
Instantiate a client using symmetric key authentication.
|
||||
|
||||
|
@ -815,7 +828,7 @@ class AbstractIoTHubModuleClient(AbstractIoTHubClient):
|
|||
gateway_hostname=gateway_hostname,
|
||||
sastoken=sastoken,
|
||||
server_verification_cert=server_verification_cert,
|
||||
**config_kwargs
|
||||
**config_kwargs,
|
||||
)
|
||||
pipeline_configuration.ensure_desired_properties = True
|
||||
|
||||
|
@ -830,7 +843,9 @@ class AbstractIoTHubModuleClient(AbstractIoTHubClient):
|
|||
return cls(mqtt_pipeline, http_pipeline)
|
||||
|
||||
@classmethod
|
||||
def create_from_x509_certificate(cls, x509: X509, hostname: str, device_id: str, module_id: str, **kwargs) -> Self:
|
||||
def create_from_x509_certificate(
|
||||
cls, x509: X509, hostname: str, device_id: str, module_id: str, **kwargs
|
||||
) -> Self:
|
||||
"""
|
||||
Instantiate a client using X509 certificate authentication.
|
||||
|
||||
|
@ -899,7 +914,9 @@ class AbstractIoTHubModuleClient(AbstractIoTHubClient):
|
|||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def invoke_method(self, method_params: dict, device_id: str, module_id: Optional[str] = None) -> None:
|
||||
def invoke_method(
|
||||
self, method_params: dict, device_id: str, module_id: Optional[str] = None
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
@property
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"""This module contains user-facing asynchronous clients for the
|
||||
Azure IoTHub Device SDK for Python.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
import logging
|
||||
import asyncio
|
||||
import deprecation
|
||||
|
@ -134,7 +134,9 @@ class GenericIoTHubClient(AbstractIoTHubClient):
|
|||
# This branch shouldn't be reached, but in case it is, log it
|
||||
logger.info("Feature ({}) already disabled - skipping".format(feature_name))
|
||||
|
||||
def _generic_receive_handler_setter(self, handler_name: str, feature_name: str, new_handler: FunctionOrCoroutine[[None], None]) -> None:
|
||||
def _generic_receive_handler_setter(
|
||||
self, handler_name: str, feature_name: str, new_handler: FunctionOrCoroutine[[None], None]
|
||||
) -> None:
|
||||
"""Set a receive handler on the handler manager and enable the corresponding feature.
|
||||
|
||||
This is a synchronous call (yes, even though this is the async client), meaning that this
|
||||
|
@ -688,7 +690,9 @@ class IoTHubModuleClient(GenericIoTHubClient, AbstractIoTHubModuleClient):
|
|||
logger.info("Input message received on: " + input_name)
|
||||
return message
|
||||
|
||||
async def invoke_method(self, method_params, device_id, module_id: Optional[str] = None) -> MethodResponse:
|
||||
async def invoke_method(
|
||||
self, method_params, device_id, module_id: Optional[str] = None
|
||||
) -> MethodResponse:
|
||||
"""Invoke a method from your client onto a device or module client, and receive the response to the method call.
|
||||
|
||||
:param dict method_params: Should contain a methodName (str), payload (str),
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"""This module contains user-facing synchronous clients for the
|
||||
Azure IoTHub Device SDK for Python.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
import logging
|
||||
import deprecation
|
||||
from .abstract_clients import (
|
||||
|
@ -25,7 +25,7 @@ from azure.iot.device.common.evented_callback import EventedCallback
|
|||
from azure.iot.device import constant as device_constant
|
||||
from .pipeline import MQTTPipeline, HTTPPipeline
|
||||
from azure.iot.device.custom_typing import FunctionOrCoroutine, StorageInfo, Twin, TwinPatch
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Optional, Union
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -134,7 +134,9 @@ class GenericIoTHubClient(AbstractIoTHubClient):
|
|||
# This branch shouldn't be reached, but in case it is, log it
|
||||
logger.info("Feature ({}) already disabled - skipping".format(feature_name))
|
||||
|
||||
def _generic_receive_handler_setter(self, handler_name: str, feature_name: str, new_handler: FunctionOrCoroutine[[None], None]) -> None:
|
||||
def _generic_receive_handler_setter(
|
||||
self, handler_name: str, feature_name: str, new_handler: FunctionOrCoroutine[[None], None]
|
||||
) -> None:
|
||||
"""Set a receive handler on the handler manager and enable the corresponding feature.
|
||||
|
||||
This is a synchronous call, meaning that this function will not return until the feature
|
||||
|
@ -354,7 +356,9 @@ class GenericIoTHubClient(AbstractIoTHubClient):
|
|||
current_version=device_constant.VERSION,
|
||||
details="We recommend that you use the .on_method_request_received property to set a handler instead",
|
||||
)
|
||||
def receive_method_request(self, method_name: Optional[str] = None, block: bool = True, timeout: Optional[int] = None) -> MethodRequest:
|
||||
def receive_method_request(
|
||||
self, method_name: Optional[str] = None, block: bool = True, timeout: Optional[int] = None
|
||||
) -> MethodRequest:
|
||||
"""Receive a method request via the Azure IoT Hub or Azure IoT Edge Hub.
|
||||
|
||||
:param str method_name: Optionally provide the name of the method to receive requests for.
|
||||
|
@ -675,7 +679,9 @@ class IoTHubModuleClient(GenericIoTHubClient, AbstractIoTHubModuleClient):
|
|||
current_version=device_constant.VERSION,
|
||||
details="We recommend that you use the .on_message_received property to set a handler instead",
|
||||
)
|
||||
def receive_message_on_input(self, input_name: str, block: bool = True, timeout: Optional[int] = None) -> Message:
|
||||
def receive_message_on_input(
|
||||
self, input_name: str, block: bool = True, timeout: Optional[int] = None
|
||||
) -> Message:
|
||||
"""Receive an input message that has been sent from another Module to a specific input.
|
||||
|
||||
:param str input_name: The input name to receive a message on.
|
||||
|
|
|
@ -8,7 +8,7 @@ This module contains user-facing asynchronous Provisioning Device Client for Azu
|
|||
Device SDK. This client uses Symmetric Key and X509 authentication to register devices with an
|
||||
IoT Hub via the Device Provisioning Service.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
from azure.iot.device.common import async_adapter
|
||||
|
|
|
@ -8,6 +8,7 @@ This module contains user-facing synchronous Provisioning Device Client for Azur
|
|||
Device SDK. This client uses Symmetric Key and X509 authentication to register devices with an
|
||||
IoT Hub via the Device Provisioning Service.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
from azure.iot.device.common.evented_callback import EventedCallback
|
||||
|
|
1
setup.py
1
setup.py
|
@ -85,6 +85,7 @@ setup(
|
|||
"requests-unixsocket>=0.1.5,<1.0.0",
|
||||
"janus",
|
||||
"PySocks",
|
||||
"typing_extensions",
|
||||
],
|
||||
python_requires=">=3.6, <4",
|
||||
packages=find_namespace_packages(where="azure-iot-device"),
|
||||
|
|
Загрузка…
Ссылка в новой задаче