anonymousland-synapse/synapse
David Robertson ffc2ee521d
Use mypy 1.0 (#15052)
* Update mypy and mypy-zope
* Remove unused ignores

These used to suppress

```
synapse/storage/engines/__init__.py:28: error: "__new__" must return a
class instance (got "NoReturn")  [misc]
```

and

```
synapse/http/matrixfederationclient.py:1270: error: "BaseException" has no attribute "reasons"  [attr-defined]
```

(note that we check `hasattr(e, "reasons")` above)

* Avoid empty body warnings, sometimes by marking methods as abstract

E.g.

```
tests/handlers/test_register.py:58: error: Missing return statement  [empty-body]
tests/handlers/test_register.py:108: error: Missing return statement  [empty-body]
```

* Suppress false positive about `JaegerConfig`

Complaint was

```
synapse/logging/opentracing.py:450: error: Function "Type[Config]" could always be true in boolean context  [truthy-function]
```

* Fix not calling `is_state()`

Oops!

```
tests/rest/client/test_third_party_rules.py:428: error: Function "Callable[[], bool]" could always be true in boolean context  [truthy-function]
```

* Suppress false positives from ParamSpecs

````
synapse/logging/opentracing.py:971: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]"  [arg-type]
synapse/logging/opentracing.py:1017: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]"  [arg-type]
````

* Drive-by improvement to `wrapping_logic` annotation

* Workaround false "unreachable" positives

See https://github.com/Shoobx/mypy-zope/issues/91

```
tests/http/test_proxyagent.py:626: error: Statement is unreachable  [unreachable]
tests/http/test_proxyagent.py:762: error: Statement is unreachable  [unreachable]
tests/http/test_proxyagent.py:826: error: Statement is unreachable  [unreachable]
tests/http/test_proxyagent.py:838: error: Statement is unreachable  [unreachable]
tests/http/test_proxyagent.py:845: error: Statement is unreachable  [unreachable]
tests/http/federation/test_matrix_federation_agent.py:151: error: Statement is unreachable  [unreachable]
tests/http/federation/test_matrix_federation_agent.py:452: error: Statement is unreachable  [unreachable]
tests/logging/test_remote_handler.py:60: error: Statement is unreachable  [unreachable]
tests/logging/test_remote_handler.py:93: error: Statement is unreachable  [unreachable]
tests/logging/test_remote_handler.py:127: error: Statement is unreachable  [unreachable]
tests/logging/test_remote_handler.py:152: error: Statement is unreachable  [unreachable]
```

* Changelog

* Tweak DBAPI2 Protocol to be accepted by mypy 1.0

Some extra context in:
- https://github.com/matrix-org/python-canonicaljson/pull/57
- https://github.com/python/mypy/issues/6002
- https://mypy.readthedocs.io/en/latest/common_issues.html#covariant-subtyping-of-mutable-protocol-members-is-rejected

* Pull in updated canonicaljson lib

so the protocol check just works

* Improve comments in opentracing

I tried to workaround the ignores but found it too much trouble.

I think the corresponding issue is
https://github.com/python/mypy/issues/12909. The mypy repo has a PR
claiming to fix this (https://github.com/python/mypy/pull/14677) which
might mean this gets resolved soon?

* Better annotation for INTERACTIVE_AUTH_CHECKERS

* Drive-by AUTH_TYPE annotation, to remove an ignore
2023-02-16 16:09:11 +00:00
..
_scripts Always notify replication when a stream advances (#14877) 2023-01-20 18:02:18 +00:00
api Update the error code for duplicate annotation (#15075) 2023-02-15 11:47:57 +00:00
app Return read-only collections from @cached methods (#13755) 2023-02-10 23:29:00 +00:00
appservice Type hints for tests.appservice (#14990) 2023-02-06 12:49:06 +00:00
config Update intentional mentions (MSC3952) to depend on exact_event_match (MSC3758). (#15037) 2023-02-16 09:51:22 -05:00
crypto Add some clarifying comments and refactor a portion of the Keyring class for readability (#14804) 2023-01-13 12:37:28 +00:00
events Change collection[str] to StrCollection in event_auth code (#14929) 2023-02-14 09:37:08 +00:00
federation Fix federated joins when the first server in the list is not in the room (#15074) 2023-02-15 13:59:06 +00:00
handlers Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
http Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
logging Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
metrics Fix logging context warnings due to common usage metrics setup (#14574) 2022-11-28 15:25:18 +00:00
module_api Fix a bug in the send_local_online_presence_to module API (#14880) 2023-01-25 21:34:37 +00:00
push Update intentional mentions (MSC3952) to depend on exact_event_match (MSC3758). (#15037) 2023-02-16 09:51:22 -05:00
replication Fix bug in replication where response is cached (#15024) 2023-02-08 16:41:55 +00:00
res Fix #11308 : Remove dependency on jquery on reCAPTCHA page (#14672) 2022-12-14 12:02:28 +00:00
rest Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
server_notices Remove redundant types from comments. (#14412) 2022-11-16 15:25:24 +00:00
spam_checker_api Fix import in module_api module and docs on the new check_event_for_spam signature (#12918) 2022-05-31 12:04:53 +02:00
state Return read-only collections from @cached methods (#13755) 2023-02-10 23:29:00 +00:00
static Add viewport directive to HTML templates to optimise for mobile (#13493) 2022-08-11 14:04:20 +01:00
storage Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
streams Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
types Implement MSC3966: Add a push rule condition to search for a value in an array. (#15045) 2023-02-14 14:02:19 -05:00
util Remove unnecessary reactor reference from _PerHostRatelimiter (#14842) 2023-01-16 13:16:19 +00:00
__init__.py Parse SYNAPSE_ASYNC_IO_REACTOR env variable & log the reactor on startup (#14092) 2022-10-07 15:19:59 +01:00
event_auth.py Change collection[str] to StrCollection in event_auth code (#14929) 2023-02-14 09:37:08 +00:00
notifier.py Fix a bug in the send_local_online_presence_to module API (#14880) 2023-01-25 21:34:37 +00:00
py.typed Mark Module API error imports as re-exported and mark Synapse as containing type annotations (#11054) 2021-10-13 08:42:41 +01:00
server.py Support for selecting the Redis logical database. (#15034) 2023-02-15 07:39:31 -05:00
visibility.py Move StateFilter to synapse.types (#14668) 2022-12-12 16:19:30 +00:00