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

Add type hints to webpushpushkin.py #271

Merged
merged 6 commits into from
Nov 16, 2021
Merged

Add type hints to webpushpushkin.py #271

merged 6 commits into from
Nov 16, 2021

Conversation

H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Nov 9, 2021

Hopefully this is a little easier to parse. Just one file. There are a few mypy errors but I believe they will be resolved once the type hints for notifications.py are accepted and merged.

@H-Shay H-Shay requested a review from a team as a code owner November 9, 2021 22:37
@H-Shay H-Shay changed the title Add type hints to webpushpushkin.py Add type hints to webpushpushkin.py Nov 9, 2021
@H-Shay H-Shay changed the title Add type hints to webpushpushkin.py Add type hints to webpushpushkin.py Nov 9, 2021
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

Mypy appears to be unhappy:

 sygnal/webpushpushkin.py:150: error: List item 0 has incompatible type "Optional[Any]"; expected "str"  [list-item]
sygnal/webpushpushkin.py:180: error: List item 0 has incompatible type "Optional[Any]"; expected "str"  [list-item]
sygnal/webpushpushkin.py:229: error: Argument 3 to "_handle_response" of "WebpushPushkin" has incompatible type "Optional[Any]"; expected "str"  [arg-type]
sygnal/webpushpushkin.py:232: error: List item 0 has incompatible type "Optional[Any]"; expected "str"  [list-item]
sygnal/webpushpushkin.py:250: error: Item "None" of "Optional[Any]" has no attribute "get"  [union-attr]

I think most of these would be fixed by marking Device.pushkin: str.
The last one seems to want an annotation for Device.data.

(Perhaps you have these locally in another commit?)

Comment on lines 24 to 26
import py_vapid
from prometheus_client import Gauge, Histogram
from py_vapid import Vapid, VapidException
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it would be nicer to import py_vapid.CaseSensitiveDict on line 26 of the RHS here, along with the other imports from that module.

sygnal/webpushpushkin.py Outdated Show resolved Hide resolved
@H-Shay
Copy link
Contributor Author

H-Shay commented Nov 10, 2021

Mypy appears to be unhappy:

So I mentioned this at the top of the PR that I think these errors will be resolved once the changes to notifications.py are merged-is the best thing to do to wait until that happens? Just wasn't sure how to manage the dependencies amongst mypy'd files in separate PR's.

@DMRobertson
Copy link
Contributor

DMRobertson commented Nov 10, 2021

Mypy appears to be unhappy:

So I mentioned this at the top of the PR that I think these errors will be resolved once the changes to notifications.py are merged-is the best thing to do to wait until that happens? Just wasn't sure how to manage the dependencies amongst mypy'd files in separate PR's.

Arg, sorry. You did indeed; I just dived straight into the diff. I think the changes you refer to are in #264 ?

FWIW, I've found this workflow to be okayish for managing this kind of dependency:

I've handled this in the past by starting a second branch based on the first change's branch. Then I target the PR at main/develop/master and mark it as a draft. That means that the PR includes both commits from the first and second branch, so I note in the description "depends on #<number>, first interesting commit is <hash>".

I typically end up

  • adding to the first until review passes
  • merging the first into main
  • rebase the second onto main
  • go through review for the second

@H-Shay H-Shay requested a review from DMRobertson November 10, 2021 19:07
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

LGTM. Maybe @squahtx wants to have their say too? Otherwise, I think this is good to go once #264 is merged.

@squahtx
Copy link
Contributor

squahtx commented Nov 10, 2021

LGTM. Maybe @squahtx wants to have their say too? Otherwise, I think this is good to go once #264 is merged.

It all looks good to me!

(I wonder if it's tractable to change Dict[str, Any] to Dict[str, object] so that mypy makes us add validation. But that's something for another time.)

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

Looking good!

@H-Shay H-Shay merged commit 5fcbbaf into main Nov 16, 2021
@H-Shay H-Shay deleted the type_hints2 branch November 16, 2021 15:50
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