MatrixSynapse/synapse/rest/media/v1
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
..
__init__.py Relax `ignore-missing-imports` for modules that have stubs now and update mypy (#11006) 2021-10-08 14:49:41 +01:00
_base.py Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
config_resource.py Use direct references for configuration variables (part 5). (#10897) 2021-09-24 07:25:21 -04:00
download_resource.py Add Cross-Origin-Resource-Policy header to thumbnail and download media endpoints (#12944) 2022-06-27 14:44:05 +01:00
filepath.py Fix media repository failing when media store path contains symlinks (#11446) 2021-12-02 16:05:24 +00:00
media_repository.py Respond with proper error responses on unknown paths. (#14621) 2022-12-08 11:37:05 -05:00
media_storage.py Typecheck tests.rest.media.v1.test_media_storage (#15008) 2023-02-07 15:24:44 +00:00
oembed.py Prefer `type(x) is int` to `isinstance(x, int)` (#14945) 2023-01-31 10:33:07 +00:00
preview_html.py fix linting error from the 1.61.1 main -> develop merge 2022-06-28 16:47:04 +01:00
preview_url_resource.py Do not wait for background updates to complete do expire URL cache. (#13657) 2022-08-30 07:15:54 -04:00
storage_provider.py Use `ParamSpec` in type hints for `synapse.logging.context` (#12150) 2022-03-08 15:58:14 +00:00
thumbnail_resource.py Provide more info why we don't have any thumbnails to serve (#13038) 2022-07-15 11:42:21 -05:00
thumbnailer.py Prefer `type(x) is int` to `isinstance(x, int)` (#14945) 2023-01-31 10:33:07 +00:00
upload_resource.py Add a `MXCUri` class to make working with mxc uri's easier. (#13162) 2022-09-15 12:57:16 +00:00