This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Require all Python to pass mypy unless specifically excluded #11272
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
26fb2da
Invert mypy selections for synapse/
callahad 53a451b
Invert mypy selections for tests/
callahad 0df2aba
Invert mypy selections for scripts-dev/
callahad 0788539
Add scripts-dev/ files not ending in .py to mypy
callahad 755ea12
Add scripts/ to mypy
callahad 8984669
Add contrib/, docker/, and synmark/ to mypy
callahad f5ebea8
Make one script in contrib/ pass mypy
callahad 4db6d96
Make setup.py pass mypy
callahad e9baf37
All Python files must pass mypy unless excluded
callahad 4aec13a
Newsfragment
callahad f2178b2
isort
callahad 6d22b83
Explain the verbose regex flag in a comment
callahad 8a973b7
Exclude all of contrib/ from mypy
callahad 515ca6b
Split up and comment the monster exclusion regex
callahad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Require all new Python files in the repository to pass mypy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,83 +9,202 @@ mypy_path = stubs | |
warn_unreachable = True | ||
local_partial_types = True | ||
no_implicit_optional = True | ||
scripts_are_modules = True | ||
|
||
# To find all folders that pass mypy you run: | ||
# | ||
# find synapse/* -type d -not -name __pycache__ -exec bash -c "mypy '{}' > /dev/null" \; -print | ||
# To find files which are Python scripts, but which do not end in .py, run: | ||
# rg --glob '!*.py' '^#!.*python' | cut -d ':' -f 1 | sort --unique | ||
|
||
files = | ||
scripts-dev/sign_json, | ||
synapse/__init__.py, | ||
synapse/api, | ||
synapse/appservice, | ||
synapse/config, | ||
synapse/crypto, | ||
synapse/event_auth.py, | ||
synapse/events, | ||
synapse/federation, | ||
synapse/groups, | ||
synapse/handlers, | ||
synapse/http, | ||
synapse/logging, | ||
synapse/metrics, | ||
synapse/module_api, | ||
synapse/notifier.py, | ||
synapse/push, | ||
synapse/replication, | ||
synapse/rest, | ||
synapse/server.py, | ||
synapse/server_notices, | ||
synapse/spam_checker_api, | ||
synapse/state, | ||
synapse/storage/__init__.py, | ||
synapse/storage/_base.py, | ||
synapse/storage/background_updates.py, | ||
synapse/storage/databases/main/appservice.py, | ||
synapse/storage/databases/main/client_ips.py, | ||
synapse/storage/databases/main/events.py, | ||
synapse/storage/databases/main/keys.py, | ||
synapse/storage/databases/main/pusher.py, | ||
synapse/storage/databases/main/registration.py, | ||
synapse/storage/databases/main/relations.py, | ||
synapse/storage/databases/main/session.py, | ||
synapse/storage/databases/main/stream.py, | ||
synapse/storage/databases/main/ui_auth.py, | ||
synapse/storage/databases/state, | ||
synapse/storage/database.py, | ||
synapse/storage/engines, | ||
synapse/storage/keys.py, | ||
synapse/storage/persist_events.py, | ||
synapse/storage/prepare_database.py, | ||
synapse/storage/purge_events.py, | ||
synapse/storage/push_rule.py, | ||
synapse/storage/relations.py, | ||
synapse/storage/roommember.py, | ||
synapse/storage/state.py, | ||
synapse/storage/types.py, | ||
synapse/storage/util, | ||
synapse/streams, | ||
synapse/types.py, | ||
synapse/util, | ||
synapse/visibility.py, | ||
tests/replication, | ||
tests/test_event_auth.py, | ||
tests/test_utils, | ||
tests/handlers/test_password_providers.py, | ||
tests/handlers/test_room.py, | ||
tests/handlers/test_room_summary.py, | ||
tests/handlers/test_send_email.py, | ||
tests/handlers/test_sync.py, | ||
tests/handlers/test_user_directory.py, | ||
tests/rest/client/test_login.py, | ||
tests/rest/client/test_auth.py, | ||
tests/rest/client/test_relations.py, | ||
tests/rest/media/v1/test_filepath.py, | ||
tests/rest/media/v1/test_oembed.py, | ||
tests/storage/test_state.py, | ||
tests/storage/test_user_directory.py, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. do we need to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yep! |
||
|
||
# Also check scripts that don't end in .py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
scripts/export_signing_key, | ||
scripts/generate_config, | ||
scripts/generate_log_config, | ||
scripts/hash_password, | ||
scripts/register_new_matrix_user, | ||
#scripts/synapse_port_db, | ||
scripts/synapse_review_recent_signups, | ||
#scripts/update_synapse_database, | ||
scripts-dev/build_debian_packages, | ||
scripts-dev/sign_json | ||
|
||
# Note: Better exclusion syntax in mypy > 0.910 | ||
# See https://github.com/python/mypy/pull/11329 | ||
# | ||
# For now, set the "(?x)" flag to use a "verbose" regex | ||
# See https://docs.python.org/3/library/re.html#re.X | ||
exclude = (?x) | ||
callahad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
^( | ||
# Exclude common virtualenv locations | ||
|env/.* | ||
|
||
# Exclude contrib/, it is unsupported | ||
|contrib/.* | ||
|
||
# Exclude docker/ files that fail mypy | ||
|docker/configure_workers_and_start.py | ||
|
||
# Exclude scripts/ files that fail mypy | ||
|scripts/move_remote_media_to_new_store.py | ||
|
||
# Exclude scripts-dev/ files that fail mypy | ||
|scripts-dev/check_signature.py | ||
|scripts-dev/definitions.py | ||
|scripts-dev/federation_client.py | ||
|scripts-dev/hash_history.py | ||
|scripts-dev/list_url_patterns.py | ||
|scripts-dev/release.py | ||
|scripts-dev/tail-synapse.py | ||
|
||
# Exclude synapse/ files that fail mypy | ||
|synapse/_scripts/ | ||
|synapse/app/ | ||
|synapse/storage/databases/__init__.py | ||
|synapse/storage/databases/main/__init__.py | ||
|synapse/storage/databases/main/account_data.py | ||
|synapse/storage/databases/main/cache.py | ||
|synapse/storage/databases/main/censor_events.py | ||
|synapse/storage/databases/main/deviceinbox.py | ||
|synapse/storage/databases/main/devices.py | ||
|synapse/storage/databases/main/directory.py | ||
|synapse/storage/databases/main/e2e_room_keys.py | ||
|synapse/storage/databases/main/end_to_end_keys.py | ||
|synapse/storage/databases/main/event_federation.py | ||
|synapse/storage/databases/main/event_push_actions.py | ||
|synapse/storage/databases/main/events_bg_updates.py | ||
|synapse/storage/databases/main/events_forward_extremities.py | ||
|synapse/storage/databases/main/events_worker.py | ||
|synapse/storage/databases/main/filtering.py | ||
|synapse/storage/databases/main/group_server.py | ||
|synapse/storage/databases/main/lock.py | ||
|synapse/storage/databases/main/media_repository.py | ||
|synapse/storage/databases/main/metrics.py | ||
|synapse/storage/databases/main/monthly_active_users.py | ||
|synapse/storage/databases/main/openid.py | ||
|synapse/storage/databases/main/presence.py | ||
|synapse/storage/databases/main/profile.py | ||
|synapse/storage/databases/main/purge_events.py | ||
|synapse/storage/databases/main/push_rule.py | ||
|synapse/storage/databases/main/receipts.py | ||
|synapse/storage/databases/main/rejections.py | ||
|synapse/storage/databases/main/room.py | ||
|synapse/storage/databases/main/room_batch.py | ||
|synapse/storage/databases/main/roommember.py | ||
|synapse/storage/databases/main/search.py | ||
|synapse/storage/databases/main/signatures.py | ||
|synapse/storage/databases/main/state.py | ||
|synapse/storage/databases/main/state_deltas.py | ||
|synapse/storage/databases/main/stats.py | ||
|synapse/storage/databases/main/tags.py | ||
|synapse/storage/databases/main/transactions.py | ||
|synapse/storage/databases/main/user_directory.py | ||
|synapse/storage/databases/main/user_erasure_store.py | ||
|synapse/storage/schema/ | ||
|
||
# Exclude synmark/ files that fail mypy | ||
|synmark/__init__.py | ||
|synmark/__main__.py | ||
|synmark/suites/logging.py | ||
|synmark/suites/lrucache.py | ||
|synmark/suites/lrucache_evict.py | ||
|
||
# Exclude tests/ files that fail mypy | ||
|tests/api/test_auth.py | ||
|tests/api/test_ratelimiting.py | ||
|tests/app/test_openid_listener.py | ||
|tests/appservice/test_scheduler.py | ||
|tests/config/test_cache.py | ||
|tests/config/test_tls.py | ||
|tests/crypto/test_keyring.py | ||
|tests/events/test_presence_router.py | ||
|tests/events/test_utils.py | ||
|tests/federation/test_federation_catch_up.py | ||
|tests/federation/test_federation_sender.py | ||
|tests/federation/test_federation_server.py | ||
|tests/federation/transport/test_knocking.py | ||
|tests/federation/transport/test_server.py | ||
|tests/handlers/test_cas.py | ||
|tests/handlers/test_directory.py | ||
|tests/handlers/test_e2e_keys.py | ||
|tests/handlers/test_federation.py | ||
|tests/handlers/test_oidc.py | ||
|tests/handlers/test_presence.py | ||
|tests/handlers/test_profile.py | ||
|tests/handlers/test_saml.py | ||
|tests/handlers/test_typing.py | ||
|tests/http/federation/test_matrix_federation_agent.py | ||
|tests/http/federation/test_srv_resolver.py | ||
|tests/http/test_fedclient.py | ||
|tests/http/test_proxyagent.py | ||
|tests/http/test_servlet.py | ||
|tests/http/test_site.py | ||
|tests/logging/__init__.py | ||
|tests/logging/test_terse_json.py | ||
|tests/module_api/test_api.py | ||
|tests/push/test_email.py | ||
|tests/push/test_http.py | ||
|tests/push/test_presentable_names.py | ||
|tests/push/test_push_rule_evaluator.py | ||
|tests/rest/admin/test_admin.py | ||
|tests/rest/admin/test_device.py | ||
|tests/rest/admin/test_media.py | ||
|tests/rest/admin/test_server_notice.py | ||
|tests/rest/admin/test_user.py | ||
|tests/rest/admin/test_username_available.py | ||
|tests/rest/client/test_account.py | ||
|tests/rest/client/test_events.py | ||
|tests/rest/client/test_filter.py | ||
|tests/rest/client/test_groups.py | ||
|tests/rest/client/test_register.py | ||
|tests/rest/client/test_report_event.py | ||
|tests/rest/client/test_rooms.py | ||
|tests/rest/client/test_third_party_rules.py | ||
|tests/rest/client/test_transactions.py | ||
|tests/rest/client/test_typing.py | ||
|tests/rest/client/utils.py | ||
|tests/rest/key/v2/test_remote_key_resource.py | ||
|tests/rest/media/v1/test_base.py | ||
|tests/rest/media/v1/test_media_storage.py | ||
|tests/rest/media/v1/test_url_preview.py | ||
|tests/scripts/test_new_matrix_user.py | ||
|tests/server.py | ||
|tests/server_notices/test_resource_limits_server_notices.py | ||
|tests/state/test_v2.py | ||
|tests/storage/test_account_data.py | ||
|tests/storage/test_appservice.py | ||
|tests/storage/test_background_update.py | ||
|tests/storage/test_base.py | ||
|tests/storage/test_client_ips.py | ||
|tests/storage/test_database.py | ||
|tests/storage/test_event_federation.py | ||
|tests/storage/test_id_generators.py | ||
|tests/storage/test_roommember.py | ||
|tests/test_metrics.py | ||
|tests/test_phone_home.py | ||
|tests/test_server.py | ||
|tests/test_state.py | ||
|tests/test_terms_auth.py | ||
|tests/test_visibility.py | ||
|tests/unittest.py | ||
|tests/util/caches/test_cached_call.py | ||
|tests/util/caches/test_deferred_cache.py | ||
|tests/util/caches/test_descriptors.py | ||
|tests/util/caches/test_response_cache.py | ||
|tests/util/caches/test_ttlcache.py | ||
|tests/util/test_async_helpers.py | ||
|tests/util/test_batching_queue.py | ||
|tests/util/test_dict_cache.py | ||
|tests/util/test_expiring_cache.py | ||
|tests/util/test_file_consumer.py | ||
|tests/util/test_linearizer.py | ||
|tests/util/test_logcontext.py | ||
|tests/util/test_lrucache.py | ||
|tests/util/test_rwlock.py | ||
|tests/util/test_wheel_timer.py | ||
|tests/utils.py | ||
)$ | ||
|
||
[mypy-synapse.api.*] | ||
disallow_untyped_defs = True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 withpython3 -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 forenv/
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/
andtests/
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.
-0.9ish.
I like this way of resolving the dispute.
Well, we could surely add other directories -
scripts-dev
,scripts
, etc. As noted elsewhere, we already have to have multiple entries in the list.