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 sygnal.py #275

Merged
merged 14 commits into from
Nov 22, 2021
Merged

Add type hints to sygnal.py #275

merged 14 commits into from
Nov 22, 2021

Conversation

H-Shay
Copy link
Contributor

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

As the title says.

@H-Shay H-Shay requested a review from a team as a code owner November 16, 2021 21:09
@H-Shay H-Shay marked this pull request as draft November 16, 2021 22:03
@H-Shay H-Shay removed the request for review from a team November 16, 2021 22:03
@H-Shay H-Shay marked this pull request as ready for review November 16, 2021 22:09
@DMRobertson DMRobertson self-assigned this Nov 17, 2021
sygnal/sygnal.py Outdated Show resolved Hide resolved
sygnal/sygnal.py Outdated Show resolved Hide resolved
sygnal/sygnal.py Outdated Show resolved Hide resolved
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. I think the only two changes I'm particularly keen on are the Tracer and the #type: ignore[code] one. The rest are very minor or comments for interest.

sygnal/sygnal.py Outdated Show resolved Hide resolved
sygnal/sygnal.py Outdated
self,
config: Dict[str, Any],
custom_reactor: SygnalReactor,
tracer: Union[Tracer, jaeger_client.Tracer] = opentracing.tracer,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should be able to just use Tracer, because jaeger_client.Tracer inherits from opentracing.Tracer.

Comment on lines 78 to 86
self.sygnal = Sygnal(config, reactor) # type: ignore
self.reactor = reactor

start_deferred = ensureDeferred(self.sygnal.make_pushkins_then_start())

while not start_deferred.called:
# we need to advance until the pushkins have started up
assert isinstance(self.sygnal.reactor, ExtendedMemoryReactorClock)
self.sygnal.reactor.advance(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we already have the reactor, maybe use self.reactor.advance etc. here and in the two cases below. I think that will let us avoid the assertions.

(Nothing wrong with as it is, just trying to keep things concise where possible)

assert isinstance(value, ApnsPushkin)
# type safety: ignore is used here due to mypy not handling monkeypatching,
# see https://github.com/python/mypy/issues/2427
value._send_notification = self.apns_pushkin_snotif # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Where possible, prefer #type: ignore[code] where code is one of mypy's error codes. See https://mypy.readthedocs.io/en/stable/error_codes.html and the two pages following it for gory details.

(but easier to remove the comment and see what the error code you get in the terminal is.)

tests/test_gcm.py Show resolved Hide resolved
sygnal/sygnal.py Show resolved Hide resolved
sygnal/sygnal.py Show resolved Hide resolved
@DMRobertson
Copy link
Contributor

Thanks @H-Shay, looks great!

@H-Shay H-Shay merged commit c5bb2dc into main Nov 22, 2021
@H-Shay H-Shay deleted the type_hints_sygnal.py branch November 22, 2021 18:32
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