Skip to content

lazy_segment_tree.py-static-type-checking#2303

Closed
kanthuc wants to merge 12 commits intoTheAlgorithms:masterfrom
kanthuc:master
Closed

lazy_segment_tree.py-static-type-checking#2303
kanthuc wants to merge 12 commits intoTheAlgorithms:masterfrom
kanthuc:master

Conversation

@kanthuc
Copy link
Copy Markdown
Contributor

@kanthuc kanthuc commented Aug 13, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@TravisBuddy
Copy link
Copy Markdown

Hey @kanthuc,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: c686fa70-dd23-11ea-b6e2-493429cddfc3

@spamegg1
Copy link
Copy Markdown
Contributor

1 E741 ambiguous variable name 'l'
4 F821 undefined name 'List'

You can rename l to something longer. Also use from typing import List.

@TravisBuddy
Copy link
Copy Markdown

Hey @kanthuc,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 7f59b910-e0f4-11ea-a6dd-d374b9ca78b0


class SegmentTree:
def __init__(self, N):
def __init__(self, N: int) -> None:
Copy link
Copy Markdown
Member

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?

def __init__(self, N: int) -> None:
self.N = N
self.st = [
self.st: List[int] = [
Copy link
Copy Markdown
Member

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
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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

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.

4 participants