This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add missing type hints to
synapse.logging.context
#11556Add missing type hints to
synapse.logging.context
#11556Changes from 1 commit
1afcfd7
d6dadd9
2f19d0c
262e91d
40a48a0
498bcd7
6d28491
a4eaf28
3c8e9d5
c305227
d32d27b
38c7390
4768efc
5cbf3c3
1886750
3f9a04b
6980f1e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
+764 seems to suggest that
f
could return adefer.Deferred[R]
too.(Is Deferred[T] considered compatible with Awaitable[T]?)
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.
It is: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/defer.py#L347
The
T
inDeferred[T]
is contravariant for some reason. If it weren't contravariant, we wouldn't need thetype: ignore
s for the overloads, for reasons I haven't figured out yet.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.
Oh! Well that makes life much easier!
Maybe because the
T
gets passed to a callback, andCallable[T, ...]
is contravariant inT
?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.
That makes sense!
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 sure about this, but also not sure if I can put my finger on why this gives me a bad feeling.
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 considered accepting a union, but decided it wasn't worth the hassle of replacing
Awaitable
s throughout synapse.I'm not sure how we'd handle other awaitables here. Create a dummy async function which
await
s them?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.
Ahh. I don't think I'd fully appreciated that
Awaitable
andCoroutine
were different concepts.Would it help to have a Synapse-only type alias for
Union[Coroutine-that-returns-T, Deferred[T]]
?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.
After some discussion in #synapse-dev, I'm going to leave the assert as is.
Creating a type alias looks tempting for correctness, but will end up propagating everywhere without much benefit, considering the lack of non-
Coroutine
, non-Deferred
awaitables.