Repository navigation
Improve typing coverage of middleware classes - #735
Conversation
I think the The problem is that the is evaluated as an expression, but the I think if you rebase this now that #737 is merged, the errors should go away. |
c9bffc5 to
74c9639
Compare
|
@LincolnPuzey this PR adds type annotations only to the |
Totally up to you. I would suggest typing the |
|
(oops clicked wrong button) |
617a357 to
87b5b43
Compare
Agreed, done. This PR requires #743 to pass CI though. |
| return [] | ||
|
|
||
| def before_ack(self, broker, message): | ||
| def before_ack(self, broker: Broker, message: Message) -> None: |
There was a problem hiding this comment.
I think for before/after ack/nack, it should use MessageProxy, rather than Message
There was a problem hiding this comment.
I have to dig some more through the code but at a first glance I didn’t quite find all the locations where these events are issued by the various brokers… 🤔
There was a problem hiding this comment.
Its inside the _ConsumerThread of the Worker
Lines 365 to 386 in 5c492e4
| raise_thread_exception(thread_id, Shutdown) | ||
|
|
||
|
|
||
| _GeventShutdownManager: Optional[Type[_ShutdownManager]] = None |
There was a problem hiding this comment.
rather than adding the if TYPE_CHECKING block,
can you try changing just this first line to
_GeventShutdownManager: Type[_ShutdownManager]
so rather than _GeventShutdownManager being either None/the actual class (two different types),
it is undefined / the actual class (which is one type).
There was a problem hiding this comment.
Hm. Looking at the code I assume that the intention of
_GeventShutdownManager = None
if is_gevent_active():
...
_GeventShutdownManager = __GeventShutdownManageris to make the name available for the middleware initialization. But both uses of _GeventShutdownManager are guarded by is_gevent_active(). So, I removed the module variable _GeventShutdownManager and renamed the class __GeventShutdownManager to _GeventShutdownManager and the code still checks and tests just fine on my local machine:
=================================== 175 passed, 131 skipped, 1 warning in 241.83s (0:04:01) ===================================
Let me push the changes, and please do take a careful look as well.
Addendum: similar pattern here:
dramatiq/dramatiq/middleware/time_limit.py
Lines 165 to 188 in 5c492e4
_GeventTimeoutManager class isn’t guarded.
There was a problem hiding this comment.
hmmm I can't see a reason for __GeventShutdownManager.
It is clearly a private name, so I'm happy to get rid of it.
Overall I think this is a good simplification.
0a83892 to
ecde645
Compare
ecde645 to
9f138cc
Compare
LincolnPuzey
left a comment
There was a problem hiding this comment.
Thanks for addressing all those comments :)
|
@LincolnPuzey do you know when you folks might release the new Dramatiq package with all the typing? |
|
@jenstroeger There is no planned date. You can always install from the master branch in the meantime |
|
@LincolnPuzey is there a cadence that you follow for releases or is the process totally ad hoc? We can't install from the master branch for a production application but we'd love to pull in this and other changes. Would it be possible to cut a release sometime in the near future? The last release was three months ago. |
Closes #521
Following up on comment #731 (comment). Alas, I am not familiar enough with Sphinx to work with the
NameErrorcaused by the missing (typing only) imports (perhaps related issue sphinx-doc/sphinx#13137).