Skip to content

Mypy config changes & enable a few more checks - #133

Open
CoolCat467 wants to merge 4 commits into
jorio:masterfrom
CoolCat467:mypy
Open

Mypy config changes & enable a few more checks#133
CoolCat467 wants to merge 4 commits into
jorio:masterfrom
CoolCat467:mypy

Conversation

@CoolCat467

Copy link
Copy Markdown

In this pull request, we tell mypy which paths to check so you can simply do mypy and check all relevant files instead of running into future cases where if things were to get more complicated, needing to change which files to check in multiple places.

Turned on warn_unreachable and dealt with new errors from this.

Turned on local_partial_types to match the results of the mypy daemon (might not be necessary, I think they said they wanted to make true the default eventually in a blog post a while ago exactly because of this)

We also show more diagnostic information for reported errors and show tracebacks in the event mypy crashes.

Also added a few missing annotations, mainly in mainwindow

Was trying out turning on warn_unused_ignores, but ran into issues with the multiple UI backend shenanigans stuff and decided not to deal with that right now, but left it as commented out because it was useful to make sure my changes weren't adding anything new.

Also show tracebacks if mypy crashes as well as error codes and column numbers for reported errors.
Comment thread gitfourchette/syntax/lexercache.py
# Extract generic class from GenericAlias, e.g. list[str] --> list
if type(dstType) is GenericAlias:
dstType = typing.get_origin(dstType)
assert not isinstance(dstType, GenericAlias)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am slightly worried about this line at runtime, would like a double check that this is correct.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, this looks correct to me because:

  • isinstance(list[str], GenericAlias) == True
  • isinstance(get_origin(list[str]), GenericAlias) == False (it's just <class 'list'>)

This also works with nested containers, e.g. get_origin(list[list[str]]) == <class 'list'>.

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.

2 participants