-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable mypy checking for unreachable code and fix instances. #8432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Check for unreachable code with mypy. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,7 +383,7 @@ async def _user_can_delete_alias(self, alias: RoomAlias, user_id: str): | |
""" | ||
creator = await self.store.get_room_alias_creator(alias.to_string()) | ||
|
||
if creator is not None and creator == user_id: | ||
if creator == user_id: | ||
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.
|
||
return True | ||
|
||
# Resolve the alias to the corresponding room. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,7 +257,7 @@ async def _async_render(self, request: Request): | |
if isinstance(raw_callback_return, (defer.Deferred, types.CoroutineType)): | ||
callback_return = await raw_callback_return | ||
else: | ||
callback_return = raw_callback_return | ||
callback_return = raw_callback_return # type: ignore | ||
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. I could not figure out how to coerce mypy into realize that this might be an awaitable or might not be. 🤷 |
||
|
||
return callback_return | ||
|
||
|
@@ -406,7 +406,7 @@ async def _async_render(self, request): | |
if isinstance(raw_callback_return, (defer.Deferred, types.CoroutineType)): | ||
callback_return = await raw_callback_return | ||
else: | ||
callback_return = raw_callback_return | ||
callback_return = raw_callback_return # type: ignore | ||
|
||
return callback_return | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
import os.path | ||
import sys | ||
|
@@ -89,14 +88,7 @@ def __call__(self, event: dict) -> None: | |
context = current_context() | ||
|
||
# Copy the context information to the log event. | ||
if context is not None: | ||
context.copy_to_twisted_log_entry(event) | ||
else: | ||
# If there's no logging context, not even the root one, we might be | ||
# starting up or it might be from non-Synapse code. Log it as if it | ||
# came from the root logger. | ||
event["request"] = None | ||
event["scope"] = None | ||
context.copy_to_twisted_log_entry(event) | ||
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.
|
||
|
||
self.observer(event) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,16 +52,6 @@ | |
) | ||
|
||
|
||
def encode_json(json_object): | ||
""" | ||
Encode a Python object as JSON and return it in a Unicode string. | ||
""" | ||
out = frozendict_json_encoder.encode(json_object) | ||
if isinstance(out, bytes): | ||
out = out.decode("utf8") | ||
Comment on lines
-60
to
-61
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. This was dealing with py2 encoder logic, which made this function fairly useless so I figured it made more sense to inline it. |
||
return out | ||
|
||
|
||
_EventCacheEntry = namedtuple("_EventCacheEntry", ("event", "redacted_event")) | ||
|
||
|
||
|
@@ -743,7 +733,9 @@ def _update_outliers_txn(self, txn, events_and_contexts): | |
logger.exception("") | ||
raise | ||
|
||
metadata_json = encode_json(event.internal_metadata.get_dict()) | ||
metadata_json = frozendict_json_encoder.encode( | ||
event.internal_metadata.get_dict() | ||
) | ||
|
||
sql = "UPDATE event_json SET internal_metadata = ? WHERE event_id = ?" | ||
txn.execute(sql, (metadata_json, event.event_id)) | ||
|
@@ -797,10 +789,10 @@ def event_dict(event): | |
{ | ||
"event_id": event.event_id, | ||
"room_id": event.room_id, | ||
"internal_metadata": encode_json( | ||
"internal_metadata": frozendict_json_encoder.encode( | ||
event.internal_metadata.get_dict() | ||
), | ||
"json": encode_json(event_dict(event)), | ||
"json": frozendict_json_encoder.encode(event_dict(event)), | ||
"format_version": event.format_version, | ||
} | ||
for event, _ in events_and_contexts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,7 +546,7 @@ async def get_recent_event_ids_for_room( | |
|
||
async def get_room_event_before_stream_ordering( | ||
self, room_id: str, stream_ordering: int | ||
) -> Tuple[int, int, str]: | ||
) -> Optional[Tuple[int, int, str]]: | ||
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. This can return |
||
"""Gets details of the first event in a room at or before a stream ordering | ||
Args: | ||
|
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.
Callers only ever checked for whether it is truth-y or not.