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 #206

Merged
merged 6 commits into from
Aug 15, 2018
Merged

Add type annotations #206

merged 6 commits into from
Aug 15, 2018

Conversation

V02460
Copy link
Contributor

@V02460 V02460 commented Aug 9, 2018

This PR adds a lot of type annotations to the code. As this alone made the type checker not happy, additionally some smaller changes were made:

  • Replace Telegram-related star imports to be more linter-friendly
  • Fix some return statements
  • Use different variable names when it’s using different types (e.g. in this method with the puppet variable changed to dbpuppet)
  • Added some basic NewTypes (MatrixUserId, MatrixRoomId, MatrixEventId, TelegramId, MatrixEvent)
  • Add an error enum to puppet.py to replace int error values
  • Changed Context to return a type safe tuple via a property

This PR does not address all the Optional discrepancies as a lot of possibly-None variables are currently accessed. Fixing this is not as easy as the rest as it is heavily related to execution logic and error handling, but I might do some smaller PRs regarding these.

For typechecking I used mypy and disabled the checking for errors with Optional. Sadly, I did only check for python 3.7 as mypy does not handle the future-fstrings in 3.5 well. This is the configuration I used:

python3 -m mypy <file> --ignore-missing-imports --no-implicit-optional --no-strict-optional --follow-imports silent`

I did test the changes on my server and it survived real-world usage of a few persons.

Copy link
Member

@tulir tulir left a comment

Choose a reason for hiding this comment

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

Thanks!

The changes mostly look good, but there are two style things to change:

I also just noticed that neither of those details are documented/configured anywhere, so sorry about that.

@tulir tulir added this to the 0.4.0 milestone Aug 13, 2018
@tulir tulir merged commit 1ef790c into mautrix:master Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants