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

Enable mypy for tools/quic/ #28916

Merged
merged 2 commits into from
May 14, 2021
Merged

Enable mypy for tools/quic/ #28916

merged 2 commits into from
May 14, 2021

Conversation

foolip
Copy link
Member

@foolip foolip commented May 9, 2021

This code was already mostly annotated, but needs updating to pass our
mypy.ini rules. A few changes are noteworthy:

  • QuicTransportProtocol.streams was removed rather than annotated,
    because it's actually unused.
  • An assert for self.handler is added after process_client_indication()
    to it clear that that it can't be None in the following loop.

Part of #28833.

@foolip
Copy link
Member Author

foolip commented May 11, 2021

@yutakahirano can you review this, given that you added this code in #22844?

This code was already mostly annotated, but needs updating to pass our
mypy.ini rules. A few changes are noteworthy:
 - QuicTransportProtocol.streams was removed rather than annotated,
   because it's actually unused.
 - An assert for self.handler is added after process_client_indication()
   to it clear that that it can't be None in the following loop.

Part of #28833.
self.connection = connection
self.global_dict = global_dict

def handle_client_indication(
self,
origin: str,
origin: Optional[str],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you keep this non-optional? Given we excluded the case where origin is None in process_client_indication, origin_string must not be none there, and hence origin must not be None here.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's an error 'Argument 1 to "handle_client_indication" of "EventHandler" has incompatible type "Optional[str]"; expected "str"' at self.handler.handle_client_indication(origin_string, query) if this is made non-optional, and at a glance it looks like origin_string could be none there, but actually it can't because of the if origin is None check. I'll see how I can convince mypy that origin_string can't be None there.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've added some asserts which should have the right effect. I'm not sure if there's a prettier way to how that two variables are linked in this way, but asserting works.

Copy link
Contributor

@yutakahirano yutakahirano left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM.

@foolip foolip merged commit f137686 into master May 14, 2021
@foolip foolip deleted the foolip/mypy-quic branch May 14, 2021 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants