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

Reading notes, initial thoughts and refactoring suggestions #1312

Closed

Conversation

gonzalo-bulnes
Copy link
Contributor

Description

Thinking aloud as I read through the code to become familiar with it. These commits are meant to be conversation starters, and the idea is that we can extract any subset of them to compose any number of actual PRs. Note that I'm making them as I read, so they come in no particular order and each commit is meant to be self-contained.

Please share your thoughts in the diffs! (That's the entire point 🙂)

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, the AppArmor profile may need to be updated. Please check as applicable:

  • I have updated the AppArmor profile
  • No update to the AppArmor profile is required for these changes
  • I don't know and would appreciate guidance

If these changes modify the database schema, you should include a database migration. Please check as applicable:

  • I have written a migration and upgraded a test database based on main and confirmed that the migration applies cleanly
  • I have written a migration but have not upgraded a test database based on main and would like the reviewer to do so
  • I need help writing a database migration
  • No database schema changes are needed

I came to really appreciate from Go that the type hints
in function signatures are often sufficient to understand
what each of the parameters and return values are.

Besides allowing precise type-checking, that allows
local variable names to become simpler (because their
type conveys information about what they are already).

Additionally, while I haven't implemented that idea
systematically yet, I find interesting that custom types
can be defined to make sense to anyone familiar with
the domain, and used to facilitate cross-functional
collaboration through shared vocabulary.
See Domain Modeling Made Functional by Scott Wlaschin
https://www.youtube.com/watch?v=2JB1_e5wZmU

As far as I understand, typing.NewType is safe to introduce
gradually because the variable will be cast automatically
when str is required. That allow to benefit from type checking
where LanguageCode is required, while keeping the change local.

See https://www.python.org/dev/peps/pep-0484#newtype-helper-function
I don't know yet how to deal with the ArgumentParser expectations
for expand_to_absolute.
I think it's good to have the magic strings grouped and visible.
If the goal of using the reverse DNS notation is to
prevent naming conflicts, then I suppose we should use
a domain nameunder the FPF control.

Caution: I haven't found any other mention of this file name
on GitHub, but I suspect this might be a breaking change?
Search https://github.com/search?q=org%3Afreedomofpress+org.freedomofthepress
Specifying when functions do not return allows Mypy to warn
when unreachable code is introduced.

Note: that feature is enabled by the option --warn-unreachable
which is not currently used. I also noticed that enabling type
ceking on this file uncovers errors in the GUI code, so I'll
address those before modifying the Mypy options.

See https://www.pyhton.org/dev/peps/pep-0484#the-noreturn-type
I added "ignore" comments when hinting at functions types
was necessary (don't know how to do that yet), or I wasn't
sure about what an approriate hint would be.
Examples: window, data, parent sometimes, datetimes...

    In the face of ambiguity, refuse the tempaton to guess. ;)

Interesting cases:

- logic.Controller.authenticated_user: without the type hint, some
  code futher down was deemed unreachable by Mypy, likely because
  it inferred a User type that always evaluates to True

- gui.main.Window.login_dialog: type checking FTW! That could have
  been a runtime error.

- gui.widgets.SourceList.get_selected_source : that one could have been
  a runtime error too.

- gui.widgets.SourceListWidgetItem: the class definition contains
  a reference to itself in a type hint. Can be passsed as a string.
  See https://www.python.org/dev/peps/pep-0484#forward-references

See https://doc.qt.io/qt-5/qwidget.html
and https://adamj.eu/tech/2021/05/25/python-type-hints-specific-type-ignore
@gonzalo-bulnes
Copy link
Contributor Author

gonzalo-bulnes commented Oct 19, 2021

We've merged everything from this PR except this commit. It is unclear what the best value would be, considering that a securedrop-client.desktop exists, and that the preferred way of starting the client is to rely on securedrop-launcher.desktop (performs an automatic update check), so I think we can close this PR.

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.

1 participant