Skip to content
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

Convert http/servlets/registerservlet.py to use async/await #372

Merged
merged 3 commits into from Jun 25, 2021

Conversation

H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Jun 24, 2021

This PR converts a function in http/servlets/registerservlet.py to use async/await. A few other files/functions needed to be changed as well.
One note: on line 109 of http/servlets/registerservlet.py, I removed the keyword yield from the call to issueToken because when I substituted await there, a few of the tests failed. After adding a breakpoint, I discovered that the call to renderPost was failing with the following message: twisted.python.failure.Failure builtins.TypeError: object str can't be used in 'await' expression. Mypy had also flagged this as a problem. I checked the function definition of issueToken and as far as I can tell it is not an asynchronous function so I am unclear as to why is was ever yielded to/awaited in the first place. Removing the await resulted in the tests all passing, so perhaps it was the right thing to do?

@clokep clokep self-requested a review June 25, 2021 11:24
@clokep
Copy link
Contributor

clokep commented Jun 25, 2021

One note: on line 109 of http/servlets/registerservlet.py, I removed the keyword yield from the call to issueToken because when I substituted await there, a few of the tests failed. After adding a breakpoint, I discovered that the call to renderPost was failing with the following message: twisted.python.failure.Failure builtins.TypeError: object str can't be used in 'await' expression. Mypy had also flagged this as a problem. I checked the function definition of issueToken and as far as I can tell it is not an asynchronous function so I am unclear as to why is was ever yielded to/awaited in the first place. Removing the await resulted in the tests all passing, so perhaps it was the right thing to do?

It's possible it returned a Deferred in the past, but inlineCallbacks let you yield on "dumb" values (I think the idea behind it is to let you switch out implementation that might return a Deferred or something). Anyway, async/await doesn't allow this and the change you made is the correct one. 👍

@clokep clokep merged commit 8ea6117 into matrix-org:main Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants