Skip to content

Commit

Permalink
fix: Typehint for CurrentMessage middleware. (#626)
Browse files Browse the repository at this point in the history
Co-authored-by: David Grigorenko <dabnd@yandex-team.ru>
  • Loading branch information
DABND19 and David Grigorenko authored May 8, 2024
1 parent 4d0cc07 commit 1e4b70d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dramatiq/middleware/current_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import contextvars
from typing import Optional
from typing import TYPE_CHECKING, Any, Optional

from .middleware import Middleware

if TYPE_CHECKING:
from ..message import Message


class CurrentMessage(Middleware):
"""Middleware that exposes the current message via a thread-local
Expand All @@ -38,11 +41,11 @@ class CurrentMessage(Middleware):
"""

_MESSAGE: contextvars.ContextVar[
Optional[dict]
"Optional[Message[Any]]"
] = contextvars.ContextVar("_MESSAGE", default=None)

@classmethod
def get_current_message(cls):
def get_current_message(cls) -> "Optional[Message[Any]]":
"""Get the message that triggered the current actor. Messages
are thread local so this returns ``None`` when called outside
of actor code.
Expand Down

0 comments on commit 1e4b70d

Please sign in to comment.