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

First pass at mypy for sydent.http #439

Merged
merged 12 commits into from
Oct 27, 2021
Merged

First pass at mypy for sydent.http #439

merged 12 commits into from
Oct 27, 2021

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Oct 27, 2021

This one was a bit of a nightmare. Lots of interaction with twisted and quite a few false starts.

I've tried to chop this up into manageable commits to make this reviewable.

David Robertson added 11 commits October 26, 2021 17:37
Rationale: I want to annotate one of these, so that we know the type of
headers (which would allow us to detect the problem fixed by #415). if I
write a stub for `IResponse` I'll have to write a stub for the entire
`iweb` interface module, which seems like a PITA.

Also: AFAICS `Response` is the only implementation of `IResponse`. So I
feel a bit naughty, but not too naughty.
otherwise we can't call `abortConnection`.
@DMRobertson DMRobertson changed the title Dmr/mypy/http/core First pass at mypy for sydent.http Oct 27, 2021
I'm alarmed that this passes locally but doesn't in CI. Let's see if
this works.
@DMRobertson DMRobertson marked this pull request as ready for review October 27, 2021 11:21
@DMRobertson DMRobertson requested a review from a team as a code owner October 27, 2021 11:21
@reivilibre reivilibre self-assigned this Oct 27, 2021
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

Thanks, that seems like a decent stab at some murky stuff.

I'm wondering what the reason was for changing IResponse to Response? I guess you must have had your reasons, but I don't see them immediately.

Comment on lines +5 to +7
# I don't like importing from _sslverify, but IOpenSSLTrustRoot isn't re-exported
# anywhere else in twisted.
from twisted.internet._sslverify import IOpenSSLTrustRoot
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should use if TYPE_CHECKING: for this since it's private?
edit: never mind, this is a stub, that's OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also use this directly in sydent, see

return twisted.internet._sslverify.OpenSSLCertificateAuthorities( # type: ignore

I don't think OpenSSLCertificateAuthorities is exported in twisted.internet.ssl. /shrug

@DMRobertson
Copy link
Contributor Author

Thanks, that seems like a decent stab at some murky stuff.

I'm wondering what the reason was for changing IResponse to Response? I guess you must have had your reasons, but I don't see them immediately.

I felt dirty doing it, but it was a compromise to avoid stubbing the entire world. See the commit message for 793bc15.

@reivilibre
Copy link
Contributor

thanks!

@DMRobertson DMRobertson merged commit 3f6a0ac into main Oct 27, 2021
@DMRobertson DMRobertson deleted the dmr/mypy/http/core branch October 27, 2021 13:57
@DMRobertson
Copy link
Contributor Author

Many thanks for reviewing @reivilibre !

DMRobertson pushed a commit that referenced this pull request Oct 27, 2021
I tried to use `Response` rather than `IResponse` to avoid having to
write a stub for the latter. There were other complications down the
line from this. It was easier to change my mind, use `stubgen` and
polish up the `iweb` stub.

See also #439 (comment)
DMRobertson pushed a commit that referenced this pull request Oct 28, 2021
I tried to use `Response` rather than `IResponse` to avoid having to
write a stub for the latter. There were other complications down the
line from this. It was easier to change my mind, use `stubgen` and
polish up the `iweb` stub.

See also #439 (comment)
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.

3 participants