Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix twisted trunk mypy errors #14012

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14012.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type annotations to be compatible with new annotations in development versions of twisted.
6 changes: 4 additions & 2 deletions synapse/handlers/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import logging
import urllib.parse
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional, cast
from xml.etree import ElementTree as ET

import attr
Expand Down Expand Up @@ -130,7 +130,9 @@ async def _validate_ticket(
except PartialDownloadError as pde:
# Twisted raises this error if the connection is closed,
# even if that's being used old-http style to signal end-of-data
body = pde.response
# Cast safety: Error.response is Optional[bytes]. but a PartialDownloadError
# always has a non-None response.
body = cast(bytes, pde.response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead assert body is not None ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, but I've done something equivalent in 149fecc.

except HttpResponseException as e:
description = (
'Authorization server responded with a "{status}" error '
Expand Down
3 changes: 3 additions & 0 deletions synapse/handlers/ui_auth/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ async def check_auth(self, authdict: dict, clientip: str) -> Any:
except PartialDownloadError as pde:
# Twisted is silly
data = pde.response
# For mypy's benefit. A general Error.response is Optional[bytes], but
# a PartialDownloadError.response should be bytes AFAICS.
assert data is not None
resp_body = json_decoder.decode(data.decode("utf-8"))

if "success" in resp_body:
Expand Down