Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

More annotations for synapse.logging, part 1 #10980

Closed
wants to merge 3 commits into from

Conversation

DMRobertson
Copy link
Contributor

Goal is to make synapse.logging pass no-untyped-defs. This is a first step.

Some work also done in #10943 in this area.

David Robertson added 3 commits October 4, 2021 14:05
Not yet passing `no-untyped-defs`. `make_deferred_yieldable` is tricky and needs more thought.
@DMRobertson DMRobertson requested a review from a team October 4, 2021 13:10
@@ -711,16 +735,19 @@ def nested_logging_context(suffix: str) -> LoggingContext:
)


def preserve_fn(f):
def preserve_fn(f: F) -> F:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want add a comment noting that the return type of F changes into a Deferred[T] if the original return type was not a Deferred.

I don't think we came to a consensus in #synapse-devs on whether it was okay to use slightly misleading type hints in this kind of situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I didn't spot that this also happens in run_in_background. Hmm, maybe this needs more thought?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be tractable to add this to our mypy plugin to make it correctly convert the return value from awaitable to deferred?

@squahtx squahtx requested a review from a team October 4, 2021 13:20
def run_in_background(f, *args, **kwargs) -> defer.Deferred:
def run_in_background(
f: Callable[..., T], *args: Any, **kwargs: Any
) -> "defer.Deferred[T]":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if T is already an awaitable

@erikjohnston erikjohnston added the X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged label Nov 1, 2021
@clokep
Copy link
Member

clokep commented Dec 16, 2021

@DMRobertson I think most of this PR was done in #11556. Should we close this for now?

@DMRobertson
Copy link
Contributor Author

Agreed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants