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 annotations for gui/main and gui/widgets #358

Closed
wants to merge 7 commits into from

Conversation

Dalek-Sec
Copy link

I left the args I had little clue about as any. I also guessed several that I was less certain about even after grepping.

Copy link
Contributor

@heartsucker heartsucker left a comment

Choose a reason for hiding this comment

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

Heya. Thanks for the contribution. There's a few places it looks like we could scope the type checking a bit tighter so we don't have to use Any so frequently. I may be wrong about these (I didn't check locally).

Also before this can be merged, you're going to need to rebase this on the latest master and squash your commits into one. Let us know if you need help with this.

"""
Show the login form.
"""
self.login_dialog = LoginDialog(self)
self.login_dialog = LoginDialog(self) # type: Optional[LoginDialog]
Copy link
Contributor

Choose a reason for hiding this comment

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

Small refactor: We should define the type of this in the __init__ method so that on visual inspection of the class, all defined attributes are in one place. Additionally, setting it to None during __init__ prevents the case where accessing it would raise an AttributeError if we don't call setup, such as in testing. I know this slightly extends the scope of your work (minor refactor, not just adding annotations).

@@ -587,7 +587,7 @@ class MainView(QWidget):
}
'''

def __init__(self, parent):
def __init__(self, parent: Any) -> None:
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 this Any can be changed to QObject and pass type checking. Maybe?

@@ -837,7 +839,7 @@ def update(self):
if self.source.document_count == 0:
self.attached.hide()

def delete_source(self, event):
def delete_source(self, event: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be QEvent (I think). We might be able to scope it tighter if we check what delete_source is attached to.

@@ -908,12 +910,12 @@ def on_toggle_offline(self):
class DeleteSourceMessageBox:
"""Use this to display operation details and confirm user choice."""

def __init__(self, parent, source, controller):
def __init__(self, parent: Any, source: Source, controller: Controller) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> QObject

self.parent = parent
super().__init__(self.parent)

def closeEvent(self, event):
def closeEvent(self, event: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> QEvent

update_signal,
message_succeeded_signal,
message_failed_signal,
update_signal: Any,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> Function[...] (you'll have to double check the args here).

def __init__(self, source_db_object, submission_db_object,
controller, file_ready_signal, align="left"):
def __init__(self, source_db_object: Source, submission_db_object: Any,
controller: Controller, file_ready_signal: Any, align: str = "left") -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

submission_db_object: Any -> File

Signal: Any -> Function[...] (you'll have to double check the args here).

@@ -1332,7 +1334,7 @@ def _on_file_download(self, file_uuid: str) -> None:
self.clear() # delete existing icon and label
self.update() # draw modified widget

def mouseReleaseEvent(self, e):
def mouseReleaseEvent(self, e: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> QEvent

@@ -1401,15 +1403,15 @@ def update_conversation(self, collection: list) -> None:
else:
self.add_file(self.source, conversation_item)

def add_file(self, source_db_object, submission_db_object):
def add_file(self, source_db_object: Source, submission_db_object: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> File

@@ -1560,7 +1562,7 @@ def _on_authentication_changed(self, authenticated: bool) -> None:
class DeleteSourceAction(QAction):
"""Use this action to delete the source record."""

def __init__(self, source, parent, controller):
def __init__(self, source: Source, parent: Any, controller: Controller) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Any -> QObject

@heartsucker
Copy link
Contributor

Additionally, there were linting errors. You can test all this locally by running pipenv run make check

./securedrop_client/gui/main.py:116:46: E261 at least two spaces before inline comment
./securedrop_client/gui/widgets.py:722:20: E261 at least two spaces before inline comment

@redshiftzero
Copy link
Contributor

hey @Dalek-Sec! let us know if you want to continue working on this (addressing @heartsucker's comments), else we can have a maintainer take it over so we can get your changes merged 🚀

@Dalek-Sec
Copy link
Author

Thank you for the review, corrections, etc.!
I cannot commit to completing this in the next few days. If you'd like to wrap this up quickly, I'd have no problem with someone else cleaning up my mess. =)
I marked my calendar to check on this at the end of the week, when I can make more time to finish up.

Dalek-Sec added 2 commits May 17, 2019 07:14
errors.

Despite efforts to commit in a working state, the linter informs me that
functions don't have an attribute `connect`.
@eloquence
Copy link
Member

@Dalek-Sec Just checking in, will you still be able to continue your work on this?

@Dalek-Sec
Copy link
Author

@Dalek-Sec Just checking in, will you still be able to continue your work on this?

If there's much left, sadly no. However, if there are only small problems remaining which I can fix on the weekend, I'm happy to finish what I started.

In other words... I have no clue what I'm doing, but I want to be helpful, but I recalled resolving all the problems, so if there's more left, I probably really don't know what I'm doing, and it may be simpler to have someone else do it.

@eloquence
Copy link
Member

Closing this for now since the original contributor was not able to finish work on it, feel free to re-open if you want to pick this up as-is in a future sprint.

@eloquence eloquence closed this May 28, 2020
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