Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Require all Python to pass mypy unless specifically excluded #11272

Closed
wants to merge 14 commits into from

Conversation

callahad
Copy link
Contributor

@callahad callahad commented Nov 8, 2021

This is a maximal response to #11271: instead of specifying files to include in mypy checking, all files are considered unless explicitly excluded.

We may want to just take the first commit instead, and focus only on the synapse/ directory. Or some middle ground.

For example: instead of getting this whole repo to pass Mypy in a single run, we may want to:

  • Explicitly exempt everything in contrib/, tests/, etc.
  • Check standalone scripts, schema migrations, etc. separately and individually, instead of as part of a single omnibus mypy run for the synapse module (doing so separately is encouraged by mypy, but the scripts_are_modules setting kind of works around it).

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Necessary becuase otherwise mypy errors with:

    There are no .py[i] files in directory 'contrib'

Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
@callahad callahad requested a review from a team as a code owner November 8, 2021 10:15
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

LGTM. We might want to ensure that the Python outside of the synapse package is linted too? But that's a separate change.

@callahad callahad requested a review from a team November 8, 2021 11:43
@callahad
Copy link
Contributor Author

callahad commented Nov 8, 2021

Would appreciate a second review before merging, since this does pretty significantly change our static type checking strategy across the repo.

Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

I also think this is sensible and preferable — good to know that you can get the exclude functionality with a monster regex.

Comment on lines +18 to +19
# Discover all .py[i] files in the repo
.,
Copy link
Member

Choose a reason for hiding this comment

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

won't this iterate into virtualenvs etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mypy won't recurse into hidden directories, so as long as your venv is in .venv/ you're golden.

Are there any other common paths we should specifically exclude?

Copy link
Contributor

Choose a reason for hiding this comment

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

The README (and maybe docs) recommends putting the venv in an env directory with python3 -m venv ./env. I did this on day one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm. Y'all should definitely switch to .venv, but I'll add an exclusion for env/ for now ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Happy to; I was just getting at that we ought to update the README! (and perhaps for sydent/sygnal too?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.venv/ and env/ are the only things in gitignore, and first is implicitly excluded by having a dot. Now that env/ is also excluded, what else would you want?

Copy link
Member

Choose a reason for hiding this comment

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

basically anything that's not checked in - my whole point is that this shouldn't break when people have things in their working copy that you don't expect.

Copy link
Member

Choose a reason for hiding this comment

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

I guess maybe it would be ok to ignore things that are in the user's various gitignore configs, but that feels a bit magical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Apache voting terms, how strongly are your feelings on this issue?

Assume the alternative would be to only cover synapse/ and tests/ with mypy, allowing other files in the repo to go without type checking.

Copy link
Member

Choose a reason for hiding this comment

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

In Apache voting terms, how strongly are your feelings on this issue?

-0.9ish.

I like this way of resolving the dispute.

Assume the alternative would be to only cover synapse/ and tests/ with mypy, allowing other files in the repo to go without type checking.

Well, we could surely add other directories - scripts-dev, scripts, etc. As noted elsewhere, we already have to have multiple entries in the list.

mypy.ini Outdated Show resolved Hide resolved
mypy.ini Show resolved Hide resolved
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Prefixing the first entry with "|" technically adds an unnecessary
exclusion for an empty path "^$", but retaining it since it will make
diffs a little nicer.

Signed-off-by: Dan Callahan <danc@element.io>
tests/util/test_itertools.py,
tests/util/test_stream_change_cache.py
# Discover all .py[i] files in the repo
.,
Copy link
Member

Choose a reason for hiding this comment

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

do we need to include .ci/scripts here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yep!

# Discover all .py[i] files in the repo
.,

# Also check scripts that don't end in .py
Copy link
Member

Choose a reason for hiding this comment

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

synctl is missing from this list.

@callahad
Copy link
Contributor Author

callahad commented Nov 9, 2021

In light of Rich's objection to targeting the entire repo, let's go with the more minimal solution in #11282

@callahad callahad closed this Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants