Skip to content

Commit 69afba7

Browse files
SepineTamclaude
andcommitted
fix: 修复代码格式以符合PEP规范
- 移除未使用的变量和导入 - 修复f-string格式问题 - 移除重复函数定义 - 修正异常处理中的冗余类型 - 修复未使用的循环变量命名 🤖 Generated with [Claude Code] Co-Authored-By: Claude <[email protected]>
1 parent 1910933 commit 69afba7

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

src/stata_mcp/webui/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ def config():
110110

111111
if all_valid:
112112
# Create backup before saving
113-
backup_path = _create_backup()
113+
_create_backup()
114114

115115
try:
116116
# Save all configuration sections
117-
for section, fields in new_config.items():
118-
for field, value in fields.items():
117+
for section_name, fields in new_config.items():
118+
for field_name, value in fields.items():
119119
if isinstance(value, dict):
120-
for sub_field, sub_value in value.items():
120+
for sub_field_name, sub_value in value.items():
121121
config_mgr.set(
122-
f'{section}.{field}.{sub_field}', str(sub_value))
122+
f'{section_name}.{field_name}.{sub_field_name}', str(sub_value))
123123
else:
124-
config_mgr.set(f'{section}.{field}', str(value))
124+
config_mgr.set(
125+
f'{section_name}.{field_name}', str(value))
125126

126127
return redirect(url_for('config', saved='1'))
127128
except Exception as e:
@@ -200,10 +201,10 @@ def import_config():
200201

201202
# Check if all validations pass
202203
all_valid = True
203-
for section, fields in validation_results.items():
204-
for field, result in fields.items():
204+
for _section_name, fields in validation_results.items():
205+
for _field_name, result in fields.items():
205206
if isinstance(result, dict):
206-
for sub_field, sub_result in result.items():
207+
for _sub_field_name, sub_result in result.items():
207208
if not sub_result['valid']:
208209
all_valid = False
209210
break

src/stata_mcp/webui/utils/config_validator.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from the complete example.toml structure.
66
"""
77

8-
import time # For backup timestamp
98
import os
109
import platform
1110
import re
@@ -72,7 +71,7 @@ def validate_output_base_path(path: str) -> Tuple[bool, str, Optional[str]]:
7271

7372
# Check write permissions
7473
if not os.access(path, os.W_OK):
75-
return False, f"Directory is not writable: {path}", f"Check directory permissions"
74+
return False, f"Directory is not writable: {path}", "Check directory permissions"
7675
else:
7776
# Try to create the directory
7877
try:
@@ -82,7 +81,7 @@ def validate_output_base_path(path: str) -> Tuple[bool, str, Optional[str]]:
8281
with open(test_file, "w") as f:
8382
f.write("test")
8483
os.remove(test_file)
85-
except (OSError, IOError) as e:
84+
except OSError as e:
8685
return False, f"Cannot create or write to directory: {path}", str(
8786
e)
8887

@@ -292,22 +291,3 @@ def create_configuration_backup(config_path: str) -> str:
292291
backup_path = f"{config_path}.backup.{timestamp}"
293292
shutil.copy2(config_path, backup_path)
294293
return backup_path
295-
296-
297-
def create_configuration_backup(config_path: str) -> str:
298-
"""
299-
Create a backup of the current configuration file.
300-
301-
Args:
302-
config_path: Path to the configuration file
303-
304-
Returns:
305-
Path to the backup file
306-
"""
307-
if not os.path.exists(config_path):
308-
return ""
309-
310-
timestamp = int(time.time())
311-
backup_path = f"{config_path}.backup.{timestamp}"
312-
shutil.copy2(config_path, backup_path)
313-
return backup_path

0 commit comments

Comments
 (0)