Skip to content

Commit

Permalink
Apply ruff autoformatter
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Verst <[email protected]>
  • Loading branch information
berndverst committed May 1, 2024
1 parent 41dcce5 commit a27eb96
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 71 deletions.
3 changes: 1 addition & 2 deletions dapr/actor/client/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def create(
actor_type: str,
actor_id: ActorId,
actor_interface: Optional[Type[ActorInterface]] = None,
) -> 'ActorProxy':
...
) -> 'ActorProxy': ...


class ActorProxyFactory(ActorFactoryBase):
Expand Down
2 changes: 1 addition & 1 deletion dapr/actor/runtime/_state_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion dapr/actor/runtime/state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions dapr/actor/runtime/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 11 additions & 14 deletions dapr/clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
1 change: 1 addition & 0 deletions dapr/clients/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import json
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions dapr/clients/grpc/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dapr/clients/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions dapr/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ class Serializer(ABC):
@abstractmethod
def serialize(
self, obj: object, custom_hook: Optional[Callable[[object], bytes]] = None
) -> bytes:
...
) -> bytes: ...

@abstractmethod
def deserialize(
self,
data: bytes,
data_type: Optional[Type] = object,
custom_hook: Optional[Callable[[bytes], object]] = None,
) -> Any:
...
) -> Any: ...
18 changes: 6 additions & 12 deletions examples/demo_actor/demo_actor/demo_actor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
1 change: 1 addition & 0 deletions examples/grpc_proxying/helloworld_service_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/grpc_proxying/helloworld_service_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/invoke-custom-data/proto/response_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/invoke-custom-data/proto/response_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ext/dapr-ext-grpc/dapr/ext/grpc/_servicier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 10 additions & 18 deletions tests/actor/fake_actor_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 11 additions & 14 deletions tests/actor/fake_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/actor/test_client_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import unittest

from unittest import mock
Expand Down
1 change: 1 addition & 0 deletions tests/clients/test_dapr_grpc_client_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/clients/test_heatlhcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ commands =
[testenv:ruff]
basepython = python3
usedevelop = False
deps = ruff==0.2.2
deps = ruff==0.4.2
commands =
ruff format

Expand Down

0 comments on commit a27eb96

Please sign in to comment.