-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Require all Python to pass mypy unless specifically excluded #11272
Conversation
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>
Signed-off-by: Dan Callahan <danc@element.io>
There was a problem hiding this 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.
Would appreciate a second review before merging, since this does pretty significantly change our static type checking strategy across the repo. |
There was a problem hiding this 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.
# Discover all .py[i] files in the repo | ||
., |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 | ||
., |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
In light of Rich's objection to targeting the entire repo, let's go with the more minimal solution in #11282 |
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:
contrib/
,tests/
, etc.synapse
module (doing so separately is encouraged by mypy, but thescripts_are_modules
setting kind of works around it).Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)