mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
tornado: Make handler_id an attribute on AsyncDjangoHandler.
This prevents us from relying on a side-effect of `allocate_handler_id` that monkey-patches `handler_id` on the `AsyncDjangoHandler` object, allowing mypy to acknowledge the existence of `handler_id` as an `int`. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
committed by
Tim Abbott
parent
f0e505d557
commit
56e1f3b725
@@ -287,7 +287,7 @@ def get_user_messages(user_profile: UserProfile) -> List[Message]:
|
|||||||
|
|
||||||
class DummyHandler(AsyncDjangoHandler):
|
class DummyHandler(AsyncDjangoHandler):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
allocate_handler_id(self)
|
self.handler_id = allocate_handler_id(self)
|
||||||
|
|
||||||
|
|
||||||
dummy_handler = DummyHandler()
|
dummy_handler = DummyHandler()
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ def get_handler_by_id(handler_id: int) -> "AsyncDjangoHandler":
|
|||||||
def allocate_handler_id(handler: "AsyncDjangoHandler") -> int:
|
def allocate_handler_id(handler: "AsyncDjangoHandler") -> int:
|
||||||
global current_handler_id
|
global current_handler_id
|
||||||
handlers[current_handler_id] = handler
|
handlers[current_handler_id] = handler
|
||||||
handler.handler_id = current_handler_id
|
handler_id = current_handler_id
|
||||||
current_handler_id += 1
|
current_handler_id += 1
|
||||||
return handler.handler_id
|
return handler_id
|
||||||
|
|
||||||
|
|
||||||
def clear_handler_by_id(handler_id: int) -> None:
|
def clear_handler_by_id(handler_id: int) -> None:
|
||||||
@@ -90,7 +90,7 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
|
|||||||
|
|
||||||
# Handler IDs are allocated here, and the handler ID map must
|
# Handler IDs are allocated here, and the handler ID map must
|
||||||
# be cleared when the handler finishes its response
|
# be cleared when the handler finishes its response
|
||||||
allocate_handler_id(self)
|
self.handler_id = allocate_handler_id(self)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
descriptor = get_descriptor_by_handler_id(self.handler_id)
|
descriptor = get_descriptor_by_handler_id(self.handler_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user