style: introduce ruff as linter and formatter (#1356)

* style: remove necessary imports

* style: fix F841

* style: fix F401

* style: fix F811

* style: fix E402

* style: fix E721

* style: fix E722

* style: fix E722

* style: fix F541

* style: ruff format

* style: all passed

* style: add ruff in deps

* style: more ignores in ruff.toml

* style: add pre-commit
This commit is contained in:
Junyan Qin (Chin)
2025-04-29 17:24:07 +08:00
committed by GitHub
parent 09e70d70e9
commit 209f16af76
240 changed files with 5307 additions and 4689 deletions

View File

@@ -1,41 +1,39 @@
from typing import Dict, Any, Optional
import dingtalk_stream
class DingTalkEvent(dict):
@staticmethod
def from_payload(payload: Dict[str, Any]) -> Optional["DingTalkEvent"]:
def from_payload(payload: Dict[str, Any]) -> Optional['DingTalkEvent']:
try:
event = DingTalkEvent(payload)
return event
except KeyError:
return None
@property
def content(self):
return self.get("Content","")
@property
def incoming_message(self) -> Optional["dingtalk_stream.chatbot.ChatbotMessage"]:
return self.get("IncomingMessage")
def content(self):
return self.get('Content', '')
@property
def incoming_message(self) -> Optional['dingtalk_stream.chatbot.ChatbotMessage']:
return self.get('IncomingMessage')
@property
def type(self):
return self.get("Type","")
return self.get('Type', '')
@property
def picture(self):
return self.get("Picture","")
return self.get('Picture', '')
@property
def audio(self):
return self.get("Audio","")
return self.get('Audio', '')
@property
def conversation(self):
return self.get("conversation_type","")
return self.get('conversation_type', '')
def __getattr__(self, key: str) -> Optional[Any]:
"""
@@ -66,4 +64,4 @@ class DingTalkEvent(dict):
Returns:
str: 字符串表示。
"""
return f"<DingTalkEvent {super().__repr__()}>"
return f'<DingTalkEvent {super().__repr__()}>'