Skip to content

Commit

Permalink
GIT-1630: fix typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanarayana committed Feb 28, 2021
1 parent 75d3043 commit f4e00da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,10 @@ def update_config(self, config: Union[bytes, str, dict, Any]):
async def publish(
self, signal: str, data: Union[Dict[str, Any], SignalData]
):
if self.get_signal_context(signal=signal):
ctx = self.get_signal_context(signal=signal)
if ctx:
await self._signal_registry.dispatch(
context=self.get_signal_context(signal=signal),
context=ctx,
data=SignalData(additional_info=data)
if not isinstance(data, SignalData)
else data,
Expand Down
2 changes: 1 addition & 1 deletion sanic/mixins/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _wrapper(handler: t.Callable):

return _wrapper

def get_signal_context(self, signal: str) -> SignalContext:
def get_signal_context(self, signal: str) -> t.Union[None, SignalContext]:
return self._ctx_mapper.get(signal)

def freeze(self, signal: t.Union[None, str] = None):
Expand Down
26 changes: 13 additions & 13 deletions sanic/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class SignalContext:

def __init__(
self,
namespace: t.AnyStr,
context: t.AnyStr,
action: t.Union[None, t.AnyStr],
namespace: str,
context: str,
action: t.Union[None, str],
):
self._namespace = namespace # type: t.AnyStr
self._context = context # type: t.AnyStr
self._action = action # type: t.Union[None, t.AnyStr]
self._namespace = namespace # type: str
self._context = context # type: str
self._action = action # type: t.Union[None, str]

def __repr__(self):
signal_name = f"{self._namespace}.{self._context}"
Expand All @@ -37,15 +37,15 @@ def __init__(
self,
request: t.Union[None, "sanic.request.Request"] = None,
response: t.Union[None, "sanic.response.HTTPResponse"] = None,
additional_info: t.Dict[t.AnyStr, t.Any] = None,
):
additional_info: t.Union[None, t.Dict[str, t.Any]] = None,
) -> None:
self._request = request # type: t.Union[None, "sanic.request.Request"]
self._response = (
response
) # type: t.Union[None, "sanic.response.HTTPResponse"]
self._additional_info = (
additional_info
) # type: t.Dict[t.AnyStr, t.Any]
) # type: t.Union[None, t.Dict[str, t.Any]]

@property
def request(self) -> t.Union[None, "sanic.request.Request"]:
Expand All @@ -56,7 +56,7 @@ def response(self) -> t.Union[None, "sanic.response.HTTPResponse"]:
return self._response

@property
def additional_info(self) -> t.Dict[t.AnyStr, t.Any]:
def additional_info(self) -> t.Union[None, t.Dict[str, t.Any]]:
return self._additional_info

def __repr__(self):
Expand All @@ -76,9 +76,9 @@ def __repr__(self):
class Signal(FrozenList):
__slots__ = ("_owner",)

def __init__(self, owner):
def __init__(self, owner: str):
super(Signal, self).__init__(items=None)
self._owner = owner
self._owner = owner # type: str

async def dispatch(
self,
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self):
def signals(self) -> t.Dict[SignalContext, Signal]:
return self._signals_map

def register(self, context: SignalContext, owner: t.AnyStr) -> None:
def register(self, context: SignalContext, owner: str) -> None:
self._signals_map[context] = Signal(owner=owner)

def subscribe(
Expand Down

0 comments on commit f4e00da

Please sign in to comment.