-
-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ Replace _types module by asgiref.typing #1044
Conversation
uvicorn/lifespan/on.py
Outdated
@@ -31,7 +49,7 @@ async def startup(self) -> None: | |||
# Keep a hard reference to prevent garbage collection | |||
# See https://github.com/encode/uvicorn/pull/972 | |||
|
|||
await self.receive_queue.put({"type": "lifespan.startup"}) | |||
await self.receive_queue.put(LifespanStartupEvent(type="lifespan.startup")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing this gives me:
uvicorn/lifespan/on.py:52: error: Type of TypedDict is ambiguous, could be any of ("LifespanStartupEvent", "LifespanShutdownEvent")
uvicorn/lifespan/on.py:52: error: Argument 1 to "put" of "Queue" has incompatible type "Dict[str, str]"; expected "Union[LifespanStartupEvent, LifespanShutdownEvent]"
If you have suggestions, I'm open to change it 😗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you do something like
lste : LifespanStartupEvent = {"type": "lifespan.startup"}
await self.receive_queue.put(lste)
it should be ok, though I have not tested it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should work. But I don't see any real improvement. Is there any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should work. But I don't see any real improvement. Is there any?
well not having a mypy error is one in my mind, I'm no mypy pro but found the TypedDict experience quite frustrating and solved most of my issues by doing that, I'm not married to it though so if you have a better idea I'm all ears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the idea would be the current implementation on the PR, but it's the same to me. I've never done what I propose on this PR tho, I always do what you suggest, so I'm going to change the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
uvicorn/lifespan/on.py
Outdated
@@ -31,7 +49,7 @@ async def startup(self) -> None: | |||
# Keep a hard reference to prevent garbage collection | |||
# See https://github.com/encode/uvicorn/pull/972 | |||
|
|||
await self.receive_queue.put({"type": "lifespan.startup"}) | |||
await self.receive_queue.put(LifespanStartupEvent(type="lifespan.startup")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you do something like
lste : LifespanStartupEvent = {"type": "lifespan.startup"}
await self.receive_queue.put(lste)
it should be ok, though I have not tested it
Co-authored-by: euri10 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks !
…move asgiref constraint) This reverts commit 926a8f5.
…move asgiref constraint) This reverts commit 926a8f5.
…move asgiref constraint) This reverts commit 926a8f5.
…move asgiref constraint) This reverts commit 926a8f5.
…move asgiref constraint) This reverts commit 926a8f5.
* ♻️ Replace _types module by asgiref.typing * ♻️ Use explicit hinting instead of TypeDict constructor * Update uvicorn/lifespan/on.py Co-authored-by: euri10 <[email protected]> Co-authored-by: euri10 <[email protected]>
Following what was discussed on #991 about adding
asgiref
.This PR only does what the title suggests, and adapts the current code in the easiest way so it doesn't break and pass mypy.