-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Mypy annotation zerver.lib.event_queue and zerver.lib.queue #958
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
Mypy annotation zerver.lib.event_queue and zerver.lib.queue #958
Conversation
Automated message from Dropbox CLA bot @cpdean, it looks like you've already signed the Dropbox CLA. Thanks! |
e73c2eb
to
abca3fd
Compare
Cool, thanks for doing this @cpdean! I merged versions of the first 3 commits (mostly just clarifying commit messages, plus a bit of cleanup to a27e50c70d5d6d675cdaafbd438cf69258ff211d to make it pass mypy checks and remove annotations not directly related to the change). Can you rebase this branch to squash the fixes to bugs introduced in this branch into the original commit that introduced them? Then it'll be a lot easier to incrementally merge the remaining pieces of this. Also, I'm curious about the need for |
@cpdean just wanted to check in on this. If you're busy, it'd be valuable to at least have an answer to the |
woops, hey I'll dig into the lambda thing tonight. making commits better On Mon, Jun 13, 2016, 12:42 Tim Abbott [email protected] wrote:
|
@timabbott okay, i've ripped out the nop_callback type things and I'm able to reproduce the error I saw earlier this month. I boiled it down to a minimal example and reported the error here: python/mypy#1710 Should we have the lambas in place and just add |
woops, my bad. made a duplicate of python/mypy#1425 |
No worries! The |
ebe3089
to
21c66f6
Compare
added the ignore notes on inline lambdas and cleaned out a third of the commits it'll be a couple days before i can take another pass but let me know what I should focus on. thanks @timabbott ! |
Some parts say Dict[text_type, text_type], others store more complicated types than strs. And somewhere someone uses an int as a key in the event dict obj.
waiting on python/mypy#1425
21c66f6
to
efbcfd1
Compare
found some more stuff to clean up and make more clear. ready for feedback, thanks again @timabbott ! |
@sharmaeklavya2 can you do a review pass on this? |
@@ -54,6 +56,7 @@ class ClientDescriptor(object): | |||
def __init__(self, user_profile_id, user_profile_email, realm_id, event_queue, | |||
event_types, client_type_name, apply_markdown=True, | |||
all_public_streams=False, lifespan_secs=0, narrow=[]): | |||
# type: (int, str, int, EventQueue, List[str], str, Optional[bool], Optional[bool], Optional[int], Iterable[Sequence[text_type]]) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_profile_email
should be text_type
, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure None
is a valid value for apply_markdown
, all_public_streams
and lifespan_secs
?
@@ -233,13 +254,15 @@ def to_dict(self): | |||
|
|||
@classmethod | |||
def from_dict(cls, d): | |||
# type: (Dict[str, Any]) -> EventQueue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d
should be Mapping[str, Any]
.
@sharmaeklavya2 this is great thank you. admittedly I hadn't read the cheat sheet before starting this. I'll be able to clean this up this weekend. |
Well I have suggested using After annotating all this code, you probably know it well enough that you can figure it out yourself what should be the correct type for a variable among |
|
||
def receiver_is_idle(user_profile_id, realm_presences): | ||
# type: (int, Dict[int, Dict]) -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realm_presences
should be Optional[Mapping[int, Mapping]]
.
@timabbott @cpdean I have reviewed this pull request. |
0196eee
to
b61e052
Compare
@sharmaeklavya2 i had missed your comment about |
@@ -56,7 +56,7 @@ class ClientDescriptor(object): | |||
def __init__(self, user_profile_id, user_profile_email, realm_id, event_queue, | |||
event_types, client_type_name, apply_markdown=True, | |||
all_public_streams=False, lifespan_secs=0, narrow=[]): | |||
# type: (int, text_type, int, EventQueue, List[text_type], text_type, bool, bool, int, Iterable[Sequence[text_type]]) -> None | |||
# type: (int, text_type, int, EventQueue, List[str], text_type, bool, bool, int, Iterable[Sequence[text_type]]) -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that self.event_types
is never modified once it is set (not just in this function, but also outside it), so maybe Sequence[str]
would be better here.
Actually there are some places where self.event_types
is being compared to None
, like in ClientDescriptor.accepts_event
. It should be Optional[Sequence[str]]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch. Fixed it.
@@ -781,7 +781,7 @@ def test_successful_subscriptions_add(self): | |||
are generated. | |||
""" | |||
self.assertNotEqual(len(self.streams), 0) # necessary for full test coverage | |||
add_streams = [u"Verona2", u"Denmark5"] | |||
add_streams = [u"Verona2", u"Denmark5"] # type: List[text_type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? Isn't mypy able to deduce this? (I haven't checked)
I ran into some problems with send_event taking either a list of ints or a list of dicts, so i figured i would change the caller's code.
Had problems with events either being a Dict with str keys and one caller who put an int key in there.
Additionally, needed to create some placeholder callbacks where mypy claimed it couldn't infer the type of lambdas.