diff --git a/dapr/actor/client/proxy.py b/dapr/actor/client/proxy.py index fd62d271..bcac2d37 100644 --- a/dapr/actor/client/proxy.py +++ b/dapr/actor/client/proxy.py @@ -34,8 +34,7 @@ def create( actor_type: str, actor_id: ActorId, actor_interface: Optional[Type[ActorInterface]] = None, - ) -> 'ActorProxy': - ... + ) -> 'ActorProxy': ... class ActorProxyFactory(ActorFactoryBase): diff --git a/dapr/actor/runtime/_state_provider.py b/dapr/actor/runtime/_state_provider.py index eb6c7a84..54f6b583 100644 --- a/dapr/actor/runtime/_state_provider.py +++ b/dapr/actor/runtime/_state_provider.py @@ -97,7 +97,7 @@ async def save_state( serialized = self._state_serializer.serialize(state.value) json_output.write(b',"value":') json_output.write(serialized) - if state.ttl_in_seconds is not None and state.ttl_in_seconds >= 0: + if state.ttl_in_seconds is not None and state.ttl_in_seconds >= 0: serialized = self._state_serializer.serialize(state.ttl_in_seconds) json_output.write(b',"metadata":{"ttlInSeconds":"') json_output.write(serialized) diff --git a/dapr/actor/runtime/state_change.py b/dapr/actor/runtime/state_change.py index b9463542..dba21e2c 100644 --- a/dapr/actor/runtime/state_change.py +++ b/dapr/actor/runtime/state_change.py @@ -35,7 +35,13 @@ class StateChangeKind(Enum): class ActorStateChange(Generic[T]): - def __init__(self, state_name: str, value: T, change_kind: StateChangeKind, ttl_in_seconds: Optional[int] = None): + def __init__( + self, + state_name: str, + value: T, + change_kind: StateChangeKind, + ttl_in_seconds: Optional[int] = None, + ): self._state_name = state_name self._value = value self._change_kind = change_kind diff --git a/dapr/actor/runtime/state_manager.py b/dapr/actor/runtime/state_manager.py index 58dcb7ea..7132175b 100644 --- a/dapr/actor/runtime/state_manager.py +++ b/dapr/actor/runtime/state_manager.py @@ -29,7 +29,9 @@ class StateMetadata(Generic[T]): - def __init__(self, value: T, change_kind: StateChangeKind, ttl_in_seconds: Optional[int] = None): + def __init__( + self, value: T, change_kind: StateChangeKind, ttl_in_seconds: Optional[int] = None + ): self._value = value self._change_kind = change_kind self._ttl_in_seconds = ttl_in_seconds @@ -136,9 +138,13 @@ async def set_state_ttl(self, state_name: str, value: T, ttl_in_seconds: Optiona self._type_name, self._actor.id.id, state_name ) if existed: - state_change_tracker[state_name] = StateMetadata(value, StateChangeKind.update, ttl_in_seconds) + state_change_tracker[state_name] = StateMetadata( + value, StateChangeKind.update, ttl_in_seconds + ) else: - state_change_tracker[state_name] = StateMetadata(value, StateChangeKind.add, ttl_in_seconds) + state_change_tracker[state_name] = StateMetadata( + value, StateChangeKind.add, ttl_in_seconds + ) async def remove_state(self, state_name: str) -> None: if not await self.try_remove_state(state_name): @@ -247,7 +253,12 @@ async def save_state(self) -> None: if state_metadata.change_kind == StateChangeKind.none: continue state_changes.append( - ActorStateChange(state_name, state_metadata.value, state_metadata.change_kind, state_metadata.ttl_in_seconds) + ActorStateChange( + state_name, + state_metadata.value, + state_metadata.change_kind, + state_metadata.ttl_in_seconds, + ) ) if state_metadata.change_kind == StateChangeKind.remove: states_to_remove.append(state_name) diff --git a/dapr/clients/base.py b/dapr/clients/base.py index dccb9624..2e590e65 100644 --- a/dapr/clients/base.py +++ b/dapr/clients/base.py @@ -27,31 +27,28 @@ class DaprActorClientBase(ABC): @abstractmethod async def invoke_method( self, actor_type: str, actor_id: str, method: str, data: Optional[bytes] = None - ) -> bytes: - ... + ) -> bytes: ... @abstractmethod - async def save_state_transactionally(self, actor_type: str, actor_id: str, data: bytes) -> None: - ... + async def save_state_transactionally( + self, actor_type: str, actor_id: str, data: bytes + ) -> None: ... @abstractmethod - async def get_state(self, actor_type: str, actor_id: str, name: str) -> bytes: - ... + async def get_state(self, actor_type: str, actor_id: str, name: str) -> bytes: ... @abstractmethod async def register_reminder( self, actor_type: str, actor_id: str, name: str, data: bytes - ) -> None: - ... + ) -> None: ... @abstractmethod - async def unregister_reminder(self, actor_type: str, actor_id: str, name: str) -> None: - ... + async def unregister_reminder(self, actor_type: str, actor_id: str, name: str) -> None: ... @abstractmethod - async def register_timer(self, actor_type: str, actor_id: str, name: str, data: bytes) -> None: - ... + async def register_timer( + self, actor_type: str, actor_id: str, name: str, data: bytes + ) -> None: ... @abstractmethod - async def unregister_timer(self, actor_type: str, actor_id: str, name: str) -> None: - ... + async def unregister_timer(self, actor_type: str, actor_id: str, name: str) -> None: ... diff --git a/dapr/clients/exceptions.py b/dapr/clients/exceptions.py index 91bc04a8..ffc662c3 100644 --- a/dapr/clients/exceptions.py +++ b/dapr/clients/exceptions.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import json from typing import Optional diff --git a/dapr/clients/grpc/_helpers.py b/dapr/clients/grpc/_helpers.py index 2f9f6006..e4f5addb 100644 --- a/dapr/clients/grpc/_helpers.py +++ b/dapr/clients/grpc/_helpers.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + from collections import namedtuple from typing import Dict, List, Union, Tuple, Optional from enum import Enum diff --git a/dapr/clients/health.py b/dapr/clients/health.py index e3daec79..eb5ea804 100644 --- a/dapr/clients/health.py +++ b/dapr/clients/health.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import urllib.request import urllib.error import time diff --git a/dapr/serializers/base.py b/dapr/serializers/base.py index 5ff1d9e8..1aa7dfc8 100644 --- a/dapr/serializers/base.py +++ b/dapr/serializers/base.py @@ -23,8 +23,7 @@ class Serializer(ABC): @abstractmethod def serialize( self, obj: object, custom_hook: Optional[Callable[[object], bytes]] = None - ) -> bytes: - ... + ) -> bytes: ... @abstractmethod def deserialize( @@ -32,5 +31,4 @@ def deserialize( data: bytes, data_type: Optional[Type] = object, custom_hook: Optional[Callable[[bytes], object]] = None, - ) -> Any: - ... + ) -> Any: ... diff --git a/examples/demo_actor/demo_actor/demo_actor_interface.py b/examples/demo_actor/demo_actor/demo_actor_interface.py index be43c2ed..51c3880c 100644 --- a/examples/demo_actor/demo_actor/demo_actor_interface.py +++ b/examples/demo_actor/demo_actor/demo_actor_interface.py @@ -18,30 +18,24 @@ class DemoActorInterface(ActorInterface): @abstractmethod @actormethod(name='GetMyData') - async def get_my_data(self) -> object: - ... + async def get_my_data(self) -> object: ... @abstractmethod @actormethod(name='SetMyData') - async def set_my_data(self, data: object) -> None: - ... + async def set_my_data(self, data: object) -> None: ... @abstractmethod @actormethod(name='ClearMyData') - async def clear_my_data(self) -> None: - ... + async def clear_my_data(self) -> None: ... @abstractmethod @actormethod(name='SetReminder') - async def set_reminder(self, enabled: bool) -> None: - ... + async def set_reminder(self, enabled: bool) -> None: ... @abstractmethod @actormethod(name='SetTimer') - async def set_timer(self, enabled: bool) -> None: - ... + async def set_timer(self, enabled: bool) -> None: ... @abstractmethod @actormethod(name='GetReentrancyStatus') - async def get_reentrancy_status(self) -> bool: - ... + async def get_reentrancy_status(self) -> bool: ... diff --git a/examples/grpc_proxying/helloworld_service_pb2.py b/examples/grpc_proxying/helloworld_service_pb2.py index e0504965..1d443bd0 100644 --- a/examples/grpc_proxying/helloworld_service_pb2.py +++ b/examples/grpc_proxying/helloworld_service_pb2.py @@ -2,6 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: helloworld_service.proto """Generated protocol buffer code.""" + from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import message as _message diff --git a/examples/grpc_proxying/helloworld_service_pb2_grpc.py b/examples/grpc_proxying/helloworld_service_pb2_grpc.py index b5403111..23ff6815 100644 --- a/examples/grpc_proxying/helloworld_service_pb2_grpc.py +++ b/examples/grpc_proxying/helloworld_service_pb2_grpc.py @@ -1,5 +1,6 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! """Client and server classes corresponding to protobuf-defined services.""" + import grpc import helloworld_service_pb2 as helloworld__service__pb2 diff --git a/examples/invoke-custom-data/proto/response_pb2.py b/examples/invoke-custom-data/proto/response_pb2.py index 373ce113..e444d1ed 100644 --- a/examples/invoke-custom-data/proto/response_pb2.py +++ b/examples/invoke-custom-data/proto/response_pb2.py @@ -2,6 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: response.proto """Generated protocol buffer code.""" + from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import message as _message diff --git a/examples/invoke-custom-data/proto/response_pb2_grpc.py b/examples/invoke-custom-data/proto/response_pb2_grpc.py index 8a939394..bf947056 100644 --- a/examples/invoke-custom-data/proto/response_pb2_grpc.py +++ b/examples/invoke-custom-data/proto/response_pb2_grpc.py @@ -1,3 +1,4 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! """Client and server classes corresponding to protobuf-defined services.""" + import grpc diff --git a/ext/dapr-ext-grpc/dapr/ext/grpc/_servicier.py b/ext/dapr-ext-grpc/dapr/ext/grpc/_servicier.py index 2217d50f..f4350373 100644 --- a/ext/dapr-ext-grpc/dapr/ext/grpc/_servicier.py +++ b/ext/dapr-ext-grpc/dapr/ext/grpc/_servicier.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import grpc from cloudevents.sdk.event import v1 # type: ignore diff --git a/tests/actor/fake_actor_classes.py b/tests/actor/fake_actor_classes.py index 50fe63fc..4452ef2e 100644 --- a/tests/actor/fake_actor_classes.py +++ b/tests/actor/fake_actor_classes.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + from dapr.serializers.json import DefaultJSONSerializer import asyncio @@ -28,8 +29,7 @@ # Fake Simple Actor Class for testing class FakeSimpleActorInterface(ActorInterface): @actormethod(name='ActorMethod') - async def actor_method(self, arg: int) -> dict: - ... + async def actor_method(self, arg: int) -> dict: ... class FakeSimpleActor(Actor, FakeSimpleActorInterface): @@ -89,40 +89,32 @@ async def receive_reminder( class FakeActorCls1Interface(ActorInterface): # Fake Actor Class deriving multiple ActorInterfaces @actormethod(name='ActorCls1Method') - async def actor_cls1_method(self, arg): - ... + async def actor_cls1_method(self, arg): ... @actormethod(name='ActorCls1Method1') - async def actor_cls1_method1(self, arg): - ... + async def actor_cls1_method1(self, arg): ... @actormethod(name='ActorCls1Method2') - async def actor_cls1_method2(self, arg): - ... + async def actor_cls1_method2(self, arg): ... class FakeActorCls2Interface(ActorInterface): @actormethod(name='ActorCls2Method') - async def actor_cls2_method(self, arg): - ... + async def actor_cls2_method(self, arg): ... @actormethod(name='ActionMethod') - async def action(self, data: object) -> str: - ... + async def action(self, data: object) -> str: ... @actormethod(name='ActionMethodWithoutArg') - async def action_no_arg(self) -> str: - ... + async def action_no_arg(self) -> str: ... class ReentrantActorInterface(ActorInterface): @actormethod(name='ReentrantMethod') - async def reentrant_method(self, data: object) -> str: - ... + async def reentrant_method(self, data: object) -> str: ... @actormethod(name='ReentrantMethodWithPassthrough') - async def reentrant_pass_through_method(self, arg): - ... + async def reentrant_pass_through_method(self, arg): ... class FakeMultiInterfacesActor( diff --git a/tests/actor/fake_client.py b/tests/actor/fake_client.py index fa5fe157..cf65d473 100644 --- a/tests/actor/fake_client.py +++ b/tests/actor/fake_client.py @@ -21,28 +21,25 @@ class FakeDaprActorClientBase(DaprActorClientBase): async def invoke_method( self, actor_type: str, actor_id: str, method: str, data: Optional[bytes] = None - ) -> bytes: - ... + ) -> bytes: ... - async def save_state_transactionally(self, actor_type: str, actor_id: str, data: bytes) -> None: - ... + async def save_state_transactionally( + self, actor_type: str, actor_id: str, data: bytes + ) -> None: ... - async def get_state(self, actor_type: str, actor_id: str, name: str) -> bytes: - ... + async def get_state(self, actor_type: str, actor_id: str, name: str) -> bytes: ... async def register_reminder( self, actor_type: str, actor_id: str, name: str, data: bytes - ) -> None: - ... + ) -> None: ... - async def unregister_reminder(self, actor_type: str, actor_id: str, name: str) -> None: - ... + async def unregister_reminder(self, actor_type: str, actor_id: str, name: str) -> None: ... - async def register_timer(self, actor_type: str, actor_id: str, name: str, data: bytes) -> None: - ... + async def register_timer( + self, actor_type: str, actor_id: str, name: str, data: bytes + ) -> None: ... - async def unregister_timer(self, actor_type: str, actor_id: str, name: str) -> None: - ... + async def unregister_timer(self, actor_type: str, actor_id: str, name: str) -> None: ... class FakeDaprActorClient(FakeDaprActorClientBase): diff --git a/tests/actor/test_client_proxy.py b/tests/actor/test_client_proxy.py index fe667d62..a736cb43 100644 --- a/tests/actor/test_client_proxy.py +++ b/tests/actor/test_client_proxy.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import unittest from unittest import mock diff --git a/tests/clients/test_dapr_grpc_client_secure.py b/tests/clients/test_dapr_grpc_client_secure.py index 41dedca1..d5e467c6 100644 --- a/tests/clients/test_dapr_grpc_client_secure.py +++ b/tests/clients/test_dapr_grpc_client_secure.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import unittest from unittest.mock import patch diff --git a/tests/clients/test_heatlhcheck.py b/tests/clients/test_heatlhcheck.py index f3be8a47..deae38cb 100644 --- a/tests/clients/test_heatlhcheck.py +++ b/tests/clients/test_heatlhcheck.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import time import unittest from unittest.mock import patch, MagicMock diff --git a/tests/clients/test_secure_http_service_invocation_client.py b/tests/clients/test_secure_http_service_invocation_client.py index f23bc11c..0ea08a10 100644 --- a/tests/clients/test_secure_http_service_invocation_client.py +++ b/tests/clients/test_secure_http_service_invocation_client.py @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + import ssl import typing from asyncio import TimeoutError diff --git a/tox.ini b/tox.ini index 39b40a5d..08153f20 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ commands = [testenv:ruff] basepython = python3 usedevelop = False -deps = ruff==0.2.2 +deps = ruff==0.4.2 commands = ruff format