Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add type hints to the spam check module #6915

Merged
merged 2 commits into from
Feb 14, 2020
Merged

Conversation

clokep
Copy link
Member

@clokep clokep commented Feb 14, 2020

This adds type hints to the spam check module and has mypy check it.

This is my first foray into typing so hopefully I didn't do anything crazy.

I spun this out of #6906 since I couldn't get it working, but I've since fixed the issue.

@clokep clokep force-pushed the clokep/spam-checker-types branch from d5a3e9d to e998c3c Compare February 14, 2020 12:22
@clokep clokep changed the title Add typing annotations to the spam check module Add type hints to the spam check module Feb 14, 2020
@clokep clokep force-pushed the clokep/spam-checker-types branch from e998c3c to 3252160 Compare February 14, 2020 12:25
@clokep clokep requested a review from a team February 14, 2020 14:07
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm! A couple of points for future ref below.

synapse/events/spamcheck.py Outdated Show resolved Hide resolved
self.hs = hs

self._store = hs.get_datastore()

@defer.inlineCallbacks
def get_state_events_in_room(self, room_id, types):
def get_state_events_in_room(self, room_id: str, types: tuple) -> defer.Deferred:
Copy link
Member

Choose a reason for hiding this comment

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

generally we've been declaring bankruptcy when trying to declare the return type of @defer.inlineCalbacks functions; the problem being that it's only the decorated version of the function that actually returns a Deferred and mypy etc get confused when you try to return state.values() instead.

Instead we either convert to async/await first, or just leave the return type unannotated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. I can just remove the return type for now if that matches what is done in other places.

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't matter. I'd just land it.

@clokep clokep merged commit 10027c8 into develop Feb 14, 2020
@clokep clokep deleted the clokep/spam-checker-types branch February 14, 2020 17:49
babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit '10027c80b':
  Add type hints to the spam check module (#6915)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants