refactor: simplify pairing check return and drop over-defensive getattr

Follow-up cleanup from /simplify-code review:
- Replace 'if X: return True / return False' with 'return X'
- Replace 'getattr(source, "chat_type", None) or ""' with 'source.chat_type'
  (SessionSource.chat_type is a non-optional str field)
This commit is contained in:
kshitij 2026-08-01 12:31:12 +05:30
parent 29b3adf902
commit 151e72a5fc
1 changed files with 2 additions and 4 deletions

View File

@ -1039,7 +1039,7 @@ class TelegramAdapter(BasePlatformAdapter):
operator explicitly opted back into pairing via a platform override
(resolution rule 1 in ``_get_unauthorized_dm_behavior``).
"""
if (getattr(source, "chat_type", None) or "") != "dm":
if source.chat_type != "dm":
return False
runner = getattr(getattr(self, "_message_handler", None), "__self__", None)
@ -1146,9 +1146,7 @@ class TelegramAdapter(BasePlatformAdapter):
if authorized:
return True
# Unauthorized DM that the gateway would pair: forward so pairing can run.
if self._should_pass_unauthorized_dm_for_pairing(source):
return True
return False
return self._should_pass_unauthorized_dm_for_pairing(source)
@classmethod
def _metadata_thread_id(cls, metadata: Optional[Dict[str, Any]]) -> Optional[str]: