-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
lazy_segment_tree.py-static-type-checking #2303
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
Conversation
pull from master
Hey @kanthuc, TravisCI finished with status TravisBuddy Request Identifier: c686fa70-dd23-11ea-b6e2-493429cddfc3 |
You can rename |
Hey @kanthuc, TravisCI finished with status TravisBuddy Request Identifier: 7f59b910-e0f4-11ea-a6dd-d374b9ca78b0 |
@@ -2,21 +2,23 @@ | |||
|
|||
|
|||
class SegmentTree: | |||
def __init__(self, N): | |||
def __init__(self, N: int) -> 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.
Why is N
in uppercase? Uppercase is reserved for constants in Python naming. Could we come up with a more self-documenting name than a single character?
self.N = N | ||
self.st = [ | ||
self.st: List[int] = [ |
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.
What is st
? Why does the reader have to guess? Can't we come up with a more self-documenting name?
self.lazy: List[int] = [ | ||
0 for i in range(0, 4 * N) | ||
] # create array to store lazy update | ||
self.flag: List[int] = [0 for i in range(0, 4 * N)] # flag for lazy update |
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.
What exactly are we flagging with this variable? This type hint is not required. The typing system can already figure out that a list comprehension creates a list and that 0 is an int. This type hint just creates cognitive clutter for the reader.
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.
Sorry, the changes I made in this pr were already included in pr#2329 which was merged recently, so I closed this pr. I'll make these changes separately and send out a new pr. Thanks
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.