Skip to content

Commit 61e67d2

Browse files
committed
refactor: add type hints to all functions
1 parent 5c96dcc commit 61e67d2

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

scripts/bump_version.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
BUMP_TYPES = ["major", "minor", "patch"]
2626

2727

28-
def get_current_version():
28+
def get_current_version() -> str:
2929
"""Extract current version by importing the version module."""
3030
if str(SRC_DIR) not in sys.path:
3131
sys.path.insert(0, str(SRC_DIR))
@@ -41,7 +41,7 @@ def get_current_version():
4141
sys.path.remove(str(SRC_DIR))
4242

4343

44-
def parse_version(version_string):
44+
def parse_version(version_string: str) -> tuple[int, int, int]:
4545
"""Parse version string, extracting major.minor.patch from PEP 440 format."""
4646
# Extract base version (major.minor.patch) from PEP 440 format
4747
# Examples: 1.2.3 -> (1,2,3), 1.2.3a1 -> (1,2,3), 1.2.3.dev1 -> (1,2,3)
@@ -56,13 +56,13 @@ def parse_version(version_string):
5656
raise ValueError(f"Invalid version format: {version_string}") from e
5757

5858

59-
def validate_version_format(version_string):
59+
def validate_version_format(version_string: str) -> None:
6060
"""Validate that the version string follows PEP 440 format."""
6161
if not re.match(PEP440_PATTERN, version_string):
6262
raise ValueError(f"Invalid version format (should follow PEP 440): {version_string}")
6363

6464

65-
def bump_version(current_version, bump_type):
65+
def bump_version(current_version: str, bump_type: str) -> str:
6666
"""Bump version based on type (major, minor, patch)."""
6767
major, minor, patch = parse_version(current_version)
6868

@@ -76,7 +76,7 @@ def bump_version(current_version, bump_type):
7676
raise ValueError(f"Invalid bump type: {bump_type}")
7777

7878

79-
def update_version(new_version):
79+
def update_version(new_version: str) -> None:
8080
"""Update version in _version.py and sync dependencies."""
8181
content = VERSION_FILE.read_text()
8282
new_content = re.sub(r'__version__ = "[^"]+"', f'__version__ = "{new_version}"', content)
@@ -89,7 +89,7 @@ def update_version(new_version):
8989
print(f"Warning: Failed to run 'uv sync': {e}")
9090

9191

92-
def handle_version_change(action_description, new_version):
92+
def handle_version_change(action_description: str, new_version: str) -> str:
9393
"""Handle version changes with common logic."""
9494
current = get_current_version()
9595
print(f"{action_description} from {current} to {new_version}")
@@ -98,15 +98,15 @@ def handle_version_change(action_description, new_version):
9898
return new_version
9999

100100

101-
def print_next_steps(version):
101+
def print_next_steps(version: str) -> None:
102102
"""Print the next steps after version update."""
103103
print("\nNext steps:")
104104
print(f"1. Commit the change: git add {FILES_TO_COMMIT} && git commit -m 'chore: bump version to {version}'")
105105
print(f"2. Create and push tag: git tag v{version} && git push origin v{version}")
106106
print("3. The GitHub Action will automatically create a release and publish to PyPI and Container Registry")
107107

108108

109-
def main():
109+
def main() -> None:
110110
"""Handle version bumping operations."""
111111
if len(sys.argv) not in [2, 3]:
112112
print(__doc__)

scripts/update_deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def compare_versions(before: dict[str, str], after: dict[str, str]) -> None:
5757
print("\n📦 No dependency versions were updated")
5858

5959

60-
def main():
60+
def main() -> None:
6161
"""Run the dependency update script."""
6262
print("🚀 Starting dependency updates...")
6363

src/modelscope_mcp_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .settings import settings
55

66

7-
def main():
7+
def main() -> None:
88
"""Serve as the main entry point for ModelScope MCP Server."""
99
from .cli import main as cli_main
1010

src/modelscope_mcp_server/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ModelScopeClient:
1919
"""Unified client for ModelScope API requests."""
2020

21-
def __init__(self, timeout: int = settings.default_api_timeout_seconds):
21+
def __init__(self, timeout: int = settings.default_api_timeout_seconds) -> None:
2222
"""Initialize the ModelScope client.
2323
2424
Args:
@@ -204,15 +204,15 @@ def _request_with_data(
204204
except requests.exceptions.Timeout as e:
205205
raise TimeoutError("Request timeout - please try again later") from e
206206

207-
def close(self):
207+
def close(self) -> None:
208208
"""Close the session."""
209209
self._session.close()
210210

211-
def __enter__(self):
211+
def __enter__(self) -> "ModelScopeClient":
212212
"""Context manager entry."""
213213
return self
214214

215-
def __exit__(self, exc_type, exc_val, exc_tb):
215+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
216216
"""Context manager exit."""
217217
self.close()
218218

0 commit comments

Comments
 (0)