Skip to content

Commit a436c57

Browse files
committed
style(scripts): apply black formatting to new files
1 parent 0b83c68 commit a436c57

3 files changed

Lines changed: 42 additions & 26 deletions

File tree

scripts/test_call.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@
66
sys.path.insert(0, "./src")
77
from telegram_mcp.mcp_server import mcp
88

9+
910
async def main():
1011
try:
1112
# FastMCP internals for testing tool calls simulate an MCP call
1213
print("Calling create_folder with payload object...")
13-
# Since 'create_folder' uses Telethon, it might crash without a real session,
14+
# Since 'create_folder' uses Telethon, it might crash without a real session,
1415
# but what we care about is if the payload binding works or if it throws a TypeError/ValidationError.
15-
16+
1617
args = {"payload": {"title": "TestFolderSchema", "include_contacts": True}}
17-
18+
1819
# FastMCP tools are stored in mcp._tools or similar. We can also just use the tool call handler.
1920
result = await mcp.call_tool("create_folder", args)
2021
print(f"Tool executed successfully. Result: {result}")
21-
22+
2223
except Exception as e:
2324
print(f"Failed: {type(e).__name__} - {e}")
2425

26+
2527
if __name__ == "__main__":
2628
asyncio.run(main())

scripts/validate_shadowing.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
import os
44
from pprint import pprint
55

6+
67
def validate_shadowing(filepath: str):
78
"""
8-
Parses a python file and ensures no local variable (or argument)
9+
Parses a python file and ensures no local variable (or argument)
910
in any function shadows a top-level module import.
1011
"""
11-
with open(filepath, 'r', encoding='utf-8') as f:
12+
with open(filepath, "r", encoding="utf-8") as f:
1213
source = f.read()
13-
14+
1415
tree = ast.parse(source, filename=filepath)
15-
16+
1617
# 1. Collect all top-level imports
1718
global_imports = set()
1819
for node in tree.body:
@@ -31,40 +32,47 @@ def validate_shadowing(filepath: str):
3132
for node in ast.walk(tree):
3233
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
3334
func_name = node.name
34-
35+
3536
# 2a. Check arguments
3637
args = []
37-
if node.args.args: args.extend(node.args.args)
38-
if node.args.posonlyargs: args.extend(node.args.posonlyargs)
39-
if node.args.kwonlyargs: args.extend(node.args.kwonlyargs)
40-
if node.args.vararg: args.append(node.args.vararg)
41-
if node.args.kwarg: args.append(node.args.kwarg)
38+
if node.args.args:
39+
args.extend(node.args.args)
40+
if node.args.posonlyargs:
41+
args.extend(node.args.posonlyargs)
42+
if node.args.kwonlyargs:
43+
args.extend(node.args.kwonlyargs)
44+
if node.args.vararg:
45+
args.append(node.args.vararg)
46+
if node.args.kwarg:
47+
args.append(node.args.kwarg)
4248

4349
for arg in args:
4450
if arg.arg in global_imports:
45-
shadow_errors.append(f"Function '{func_name}' has parameter '{arg.arg}' shadowing an import.")
51+
shadow_errors.append(
52+
f"Function '{func_name}' has parameter '{arg.arg}' shadowing an import."
53+
)
4654

4755
# 2b. Check local assignments (any Name with Store context)
4856
for child in ast.walk(node):
4957
if isinstance(child, ast.Name) and isinstance(child.ctx, ast.Store):
5058
if child.id in global_imports:
51-
shadow_errors.append(f"Function '{func_name}' has local variable '{child.id}' shadowing an import. Line {getattr(child, 'lineno', '?')}")
59+
shadow_errors.append(
60+
f"Function '{func_name}' has local variable '{child.id}' shadowing an import. Line {getattr(child, 'lineno', '?')}"
61+
)
5262

5363
if shadow_errors:
5464
print(f"\n[CRITICAL FATAL] Shadowing detected in {filepath}:")
5565
for err in shadow_errors:
5666
print(f" - {err}")
5767
return False
58-
68+
5969
print(f"[{os.path.basename(filepath)}] AST Shadowing Check: PASSED \u2705")
6070
return True
6171

72+
6273
if __name__ == "__main__":
63-
files_to_check = [
64-
"src/telegram_mcp/mcp_server.py",
65-
"src/telegram_mcp/client.py"
66-
]
67-
74+
files_to_check = ["src/telegram_mcp/mcp_server.py", "src/telegram_mcp/client.py"]
75+
6876
all_passed = True
6977
for f in files_to_check:
7078
full_path = os.path.join(os.getcwd(), f)
@@ -73,8 +81,8 @@ def validate_shadowing(filepath: str):
7381
all_passed = False
7482
else:
7583
print(f"Warning: File {f} not found.")
76-
84+
7785
if not all_passed:
7886
sys.exit(1)
79-
87+
8088
sys.exit(0)

src/telegram_mcp/dtos.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from typing import List, Optional, Union
22
from pydantic import BaseModel, Field
33

4+
45
class ImportContactsPayload(BaseModel):
56
contact_list: list = Field(
67
description="A list of contacts. Each contact should be a dict with phone, first_name, last_name."
78
)
89

10+
911
class CreateFolderPayload(BaseModel):
1012
title: str = Field(description="Folder name (required)")
11-
emoticon: Optional[str] = Field(default=None, description="Folder emoji (optional, e.g., '📁', '🏠', '💼')")
13+
emoticon: Optional[str] = Field(
14+
default=None, description="Folder emoji (optional, e.g., '📁', '🏠', '💼')"
15+
)
1216
chat_ids: Optional[List[Union[int, str]]] = Field(
1317
default=None, description="List of chat IDs or usernames to include (optional)"
1418
)
@@ -19,4 +23,6 @@ class CreateFolderPayload(BaseModel):
1923
include_bots: bool = Field(default=False, description="Include all bots")
2024
exclude_muted: bool = Field(default=False, description="Exclude muted chats")
2125
exclude_read: bool = Field(default=False, description="Exclude read chats")
22-
exclude_archived: bool = Field(default=True, description="Exclude archived chats (default True)")
26+
exclude_archived: bool = Field(
27+
default=True, description="Exclude archived chats (default True)"
28+
)

0 commit comments

Comments
 (0)