Skip to content

Commit

Permalink
Update Ruff config to use single quotes
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Verst <[email protected]>
  • Loading branch information
berndverst committed Jan 19, 2024
1 parent 9660735 commit 3555605
Show file tree
Hide file tree
Showing 142 changed files with 2,635 additions and 2,633 deletions.
16 changes: 8 additions & 8 deletions dapr/actor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@


__all__ = [
"ActorInterface",
"ActorProxy",
"ActorProxyFactory",
"ActorId",
"Actor",
"ActorRuntime",
"Remindable",
"actormethod",
'ActorInterface',
'ActorProxy',
'ActorProxyFactory',
'ActorId',
'Actor',
'ActorRuntime',
'Remindable',
'actormethod',
]
22 changes: 11 additions & 11 deletions dapr/actor/client/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from dapr.conf import settings

# Actor factory Callable type hint.
ACTOR_FACTORY_CALLBACK = Callable[[ActorInterface, str, str], "ActorProxy"]
ACTOR_FACTORY_CALLBACK = Callable[[ActorInterface, str, str], 'ActorProxy']


class ActorFactoryBase(ABC):
Expand All @@ -34,7 +34,7 @@ def create(
actor_type: str,
actor_id: ActorId,
actor_interface: Optional[Type[ActorInterface]] = None,
) -> "ActorProxy":
) -> 'ActorProxy':
...


Expand All @@ -60,23 +60,23 @@ def create(
actor_type: str,
actor_id: ActorId,
actor_interface: Optional[Type[ActorInterface]] = None,
) -> "ActorProxy":
) -> 'ActorProxy':
return ActorProxy(
self._dapr_client, actor_type, actor_id, actor_interface, self._message_serializer
)


class CallableProxy:
def __init__(
self, proxy: "ActorProxy", attr_call_type: Dict[str, Any], message_serializer: Serializer
self, proxy: 'ActorProxy', attr_call_type: Dict[str, Any], message_serializer: Serializer
):
self._proxy = proxy
self._attr_call_type = attr_call_type
self._message_serializer = message_serializer

async def __call__(self, *args, **kwargs) -> Any:
if len(args) > 1:
raise ValueError("does not support multiple arguments")
raise ValueError('does not support multiple arguments')

bytes_data = None
if len(args) > 0:
Expand All @@ -85,9 +85,9 @@ async def __call__(self, *args, **kwargs) -> Any:
else:
bytes_data = self._message_serializer.serialize(args[0])

rtnval = await self._proxy.invoke_method(self._attr_call_type["actor_method"], bytes_data)
rtnval = await self._proxy.invoke_method(self._attr_call_type['actor_method'], bytes_data)

return self._message_serializer.deserialize(rtnval, self._attr_call_type["return_types"])
return self._message_serializer.deserialize(rtnval, self._attr_call_type['return_types'])


class ActorProxy:
Expand Down Expand Up @@ -134,7 +134,7 @@ def create(
actor_id: ActorId,
actor_interface: Optional[Type[ActorInterface]] = None,
actor_proxy_factory: Optional[ActorFactoryBase] = None,
) -> "ActorProxy":
) -> 'ActorProxy':
"""Creates ActorProxy client to call actor.
Args:
Expand Down Expand Up @@ -168,7 +168,7 @@ async def invoke_method(self, method: str, raw_body: Optional[bytes] = None) ->
"""

if raw_body is not None and not isinstance(raw_body, bytes):
raise ValueError(f"raw_body {type(raw_body)} is not bytes type")
raise ValueError(f'raw_body {type(raw_body)} is not bytes type')

return await self._dapr_client.invoke_method(
self._actor_type, str(self._actor_id), method, raw_body
Expand All @@ -189,14 +189,14 @@ def __getattr__(self, name: str) -> CallableProxy:
AttributeError: method is not defined in Actor interface.
"""
if not self._actor_interface:
raise ValueError("actor_interface is not set. use invoke method.")
raise ValueError('actor_interface is not set. use invoke method.')

if name not in self._dispatchable_attr:
get_dispatchable_attrs_from_interface(self._actor_interface, self._dispatchable_attr)

attr_call_type = self._dispatchable_attr.get(name)
if attr_call_type is None:
raise AttributeError(f"{self._actor_interface.__class__} has no attribute {name}")
raise AttributeError(f'{self._actor_interface.__class__} has no attribute {name}')

if name not in self._callable_proxies:
self._callable_proxies[name] = CallableProxy(
Expand Down
2 changes: 1 addition & 1 deletion dapr/actor/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ActorId:

def __init__(self, actor_id: str):
if not isinstance(actor_id, str):
raise TypeError(f"Argument actor_id must be of type str, not {type(actor_id)}")
raise TypeError(f'Argument actor_id must be of type str, not {type(actor_id)}')
self._id = actor_id

@classmethod
Expand Down
22 changes: 11 additions & 11 deletions dapr/actor/runtime/_reminder_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
self._ttl = ttl

if not isinstance(state, bytes):
raise ValueError(f"only bytes are allowed for state: {type(state)}")
raise ValueError(f'only bytes are allowed for state: {type(state)}')

self._state = state

Expand Down Expand Up @@ -92,27 +92,27 @@ def as_dict(self) -> Dict[str, Any]:
if self._state is not None:
encoded_state = base64.b64encode(self._state)
reminderDict: Dict[str, Any] = {
"reminderName": self._reminder_name,
"dueTime": self._due_time,
"period": self._period,
"data": encoded_state.decode("utf-8"),
'reminderName': self._reminder_name,
'dueTime': self._due_time,
'period': self._period,
'data': encoded_state.decode('utf-8'),
}

if self._ttl is not None:
reminderDict.update({"ttl": self._ttl})
reminderDict.update({'ttl': self._ttl})

return reminderDict

@classmethod
def from_dict(cls, reminder_name: str, obj: Dict[str, Any]) -> "ActorReminderData":
def from_dict(cls, reminder_name: str, obj: Dict[str, Any]) -> 'ActorReminderData':
"""Creates :class:`ActorReminderData` object from dict object."""
b64encoded_state = obj.get("data")
b64encoded_state = obj.get('data')
state_bytes = None
if b64encoded_state is not None and len(b64encoded_state) > 0:
state_bytes = base64.b64decode(b64encoded_state)
if "ttl" in obj:
if 'ttl' in obj:
return ActorReminderData(
reminder_name, state_bytes, obj["dueTime"], obj["period"], obj["ttl"]
reminder_name, state_bytes, obj['dueTime'], obj['period'], obj['ttl']
)
else:
return ActorReminderData(reminder_name, state_bytes, obj["dueTime"], obj["period"])
return ActorReminderData(reminder_name, state_bytes, obj['dueTime'], obj['period'])
18 changes: 9 additions & 9 deletions dapr/actor/runtime/_state_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

# Mapping StateChangeKind to Dapr State Operation
_MAP_CHANGE_KIND_TO_OPERATION = {
StateChangeKind.remove: b"delete",
StateChangeKind.add: b"upsert",
StateChangeKind.update: b"upsert",
StateChangeKind.remove: b'delete',
StateChangeKind.add: b'upsert',
StateChangeKind.update: b'upsert',
}


Expand Down Expand Up @@ -79,24 +79,24 @@ async def save_state(
"""

json_output = io.BytesIO()
json_output.write(b"[")
json_output.write(b'[')
first_state = True
for state in state_changes:
if not first_state:
json_output.write(b",")
operation = _MAP_CHANGE_KIND_TO_OPERATION.get(state.change_kind) or b""
json_output.write(b',')
operation = _MAP_CHANGE_KIND_TO_OPERATION.get(state.change_kind) or b''
json_output.write(b'{"operation":"')
json_output.write(operation)
json_output.write(b'","request":{"key":"')
json_output.write(state.state_name.encode("utf-8"))
json_output.write(state.state_name.encode('utf-8'))
json_output.write(b'"')
if state.value is not None:
serialized = self._state_serializer.serialize(state.value)
json_output.write(b',"value":')
json_output.write(serialized)
json_output.write(b"}}")
json_output.write(b'}}')
first_state = False
json_output.write(b"]")
json_output.write(b']')
data = json_output.getvalue()
json_output.close()
await self._state_client.save_state_transactionally(actor_type, actor_id, data)
10 changes: 5 additions & 5 deletions dapr/actor/runtime/_timer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def as_dict(self) -> Dict[str, Any]:
"""

timerDict: Dict[str, Any] = {
"callback": self._callback,
"data": self._state,
"dueTime": self._due_time,
"period": self._period,
'callback': self._callback,
'data': self._state,
'dueTime': self._due_time,
'period': self._period,
}

if self._ttl:
timerDict.update({"ttl": self._ttl})
timerDict.update({'ttl': self._ttl})

return timerDict
14 changes: 7 additions & 7 deletions dapr/actor/runtime/_type_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ActorTypeInformation:
def __init__(
self,
name: str,
implementation_class: Type["Actor"],
actor_bases: List[Type["ActorInterface"]],
implementation_class: Type['Actor'],
actor_bases: List[Type['ActorInterface']],
):
self._name = name
self._impl_type = implementation_class
Expand All @@ -44,12 +44,12 @@ def type_name(self) -> str:
return self._name

@property
def implementation_type(self) -> Type["Actor"]:
def implementation_type(self) -> Type['Actor']:
"""Returns Actor implementation type."""
return self._impl_type

@property
def actor_interfaces(self) -> List[Type["ActorInterface"]]:
def actor_interfaces(self) -> List[Type['ActorInterface']]:
"""Returns the list of :class:`ActorInterface` of this type."""
return self._actor_bases

Expand All @@ -58,7 +58,7 @@ def is_remindable(self) -> bool:
return Remindable in self._impl_type.__bases__

@classmethod
def create(cls, actor_class: Type["Actor"]) -> "ActorTypeInformation":
def create(cls, actor_class: Type['Actor']) -> 'ActorTypeInformation':
"""Creates :class:`ActorTypeInformation` for actor_class.
Args:
Expand All @@ -69,10 +69,10 @@ def create(cls, actor_class: Type["Actor"]) -> "ActorTypeInformation":
and actor base class deriving :class:`ActorInterface`
"""
if not is_dapr_actor(actor_class):
raise ValueError(f"{actor_class.__name__} is not actor")
raise ValueError(f'{actor_class.__name__} is not actor')

actors = get_actor_interfaces(actor_class)
if len(actors) == 0:
raise ValueError(f"{actor_class.__name__} does not implement ActorInterface")
raise ValueError(f'{actor_class.__name__} does not implement ActorInterface')

return ActorTypeInformation(actor_class.__name__, actor_class, actors)
26 changes: 13 additions & 13 deletions dapr/actor/runtime/_type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def get_class_method_args(func: Any) -> List[str]:
args = func.__code__.co_varnames[: func.__code__.co_argcount]

# Exclude self, cls arguments
if args[0] == "self" or args[0] == "cls":
if args[0] == 'self' or args[0] == 'cls':
args = args[1:]
return list(args)


def get_method_arg_types(func: Any) -> List[Type]:
annotations = getattr(func, "__annotations__")
annotations = getattr(func, '__annotations__')
args = get_class_method_args(func)
arg_types = []
for arg_name in args:
Expand All @@ -39,26 +39,26 @@ def get_method_arg_types(func: Any) -> List[Type]:


def get_method_return_types(func: Any) -> Type:
annotations = getattr(func, "__annotations__")
if len(annotations) == 0 or not annotations["return"]:
annotations = getattr(func, '__annotations__')
if len(annotations) == 0 or not annotations['return']:
return object
return annotations["return"]
return annotations['return']


def get_dispatchable_attrs_from_interface(
actor_interface: Type[ActorInterface], dispatch_map: Dict[str, Any]
) -> None:
for attr, v in actor_interface.__dict__.items():
if attr.startswith("_") or not callable(v):
if attr.startswith('_') or not callable(v):
continue
actor_method_name = getattr(v, "__actormethod__") if hasattr(v, "__actormethod__") else attr
actor_method_name = getattr(v, '__actormethod__') if hasattr(v, '__actormethod__') else attr

dispatch_map[actor_method_name] = {
"actor_method": actor_method_name,
"method_name": attr,
"arg_names": get_class_method_args(v),
"arg_types": get_method_arg_types(v),
"return_types": get_method_return_types(v),
'actor_method': actor_method_name,
'method_name': attr,
'arg_names': get_class_method_args(v),
'arg_types': get_method_arg_types(v),
'return_types': get_method_return_types(v),
}


Expand All @@ -77,7 +77,7 @@ def get_dispatchable_attrs(actor_class: Type[Actor]) -> Dict[str, Any]:
# Find all user actor interfaces derived from ActorInterface
actor_interfaces = get_actor_interfaces(actor_class)
if len(actor_interfaces) == 0:
raise ValueError(f"{actor_class.__name__} has not inherited from ActorInterface")
raise ValueError(f'{actor_class.__name__} has not inherited from ActorInterface')

# Find all dispatchable attributes
dispatch_map: Dict[str, Any] = {}
Expand Down
2 changes: 1 addition & 1 deletion dapr/actor/runtime/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def runtime_ctx(self) -> ActorRuntimeContext:
return self._runtime_ctx

def __get_new_timer_name(self):
return f"{self.id}_Timer_{uuid.uuid4()}"
return f'{self.id}_Timer_{uuid.uuid4()}'

async def register_timer(
self,
Expand Down
Loading

0 comments on commit 3555605

Please sign in to comment.