Misc typing fixes for tests, part 1 of N (#11323)

* Annotate HomeserverTestCase.servlets
* Correct annotation of federation_auth_origin
* Use AnyStr custom_headers instead of a Union

This allows (str, str) and (bytes, bytes).
This disallows (str, bytes) and (bytes, str)

* DomainSpecificString.SIGIL is a ClassVar
This commit is contained in:
David Robertson 2021-11-12 15:50:54 +00:00 committed by GitHub
parent 95547e5300
commit 4c96ce396e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 29 deletions

View file

@ -19,7 +19,17 @@ import json
import re
import time
import urllib.parse
from typing import Any, Dict, Iterable, Mapping, MutableMapping, Optional, Tuple, Union
from typing import (
Any,
AnyStr,
Dict,
Iterable,
Mapping,
MutableMapping,
Optional,
Tuple,
Union,
)
from unittest.mock import patch
import attr
@ -53,9 +63,7 @@ class RestHelper:
tok: Optional[str] = None,
expect_code: int = 200,
extra_content: Optional[Dict] = None,
custom_headers: Optional[
Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
] = None,
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
) -> str:
"""
Create a room.
@ -227,9 +235,7 @@ class RestHelper:
txn_id=None,
tok=None,
expect_code=200,
custom_headers: Optional[
Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
] = None,
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
):
if body is None:
body = "body_text_here"
@ -418,7 +424,7 @@ class RestHelper:
path,
content=image_data,
access_token=tok,
custom_headers=[(b"Content-Length", str(image_length))],
custom_headers=[("Content-Length", str(image_length))],
)
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (