Skip to content

Commit 0fbf795

Browse files
author
Test User
committed
fix: use typing module for Python 3.9 compatible type hints
1 parent d0a2045 commit 0fbf795

4 files changed

Lines changed: 80 additions & 10 deletions

File tree

src/ab_cli/commands/changelog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import subprocess
99
import sys
10+
from typing import Dict, List
1011

1112
from ab_cli.core.config import get_language
1213
from ab_cli.utils import (
@@ -42,7 +43,7 @@ def get_commit_count(range_spec: str) -> int:
4243
return 0
4344

4445

45-
def parse_commits(commits_str: str) -> list[dict]:
46+
def parse_commits(commits_str: str) -> List[Dict]:
4647
"""Parse commits into structured format."""
4748
commits = []
4849
for line in commits_str.split('\n'):
@@ -59,7 +60,7 @@ def parse_commits(commits_str: str) -> list[dict]:
5960
return commits
6061

6162

62-
def categorize_commits(commits: list[dict]) -> dict[str, list[dict]]:
63+
def categorize_commits(commits: List[Dict]) -> Dict[str, List[Dict]]:
6364
"""Categorize commits by type (feat, fix, etc.)."""
6465
categories = {
6566
'features': [],

src/ab_cli/commands/gen_script.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import tempfile
1414
from pathlib import Path
15+
from typing import List
1516

1617
from ab_cli.core.config import get_language
1718
from ab_cli.utils import (
@@ -25,8 +26,34 @@
2526
)
2627

2728

28-
def run_cmd(cmd: list[str], default: str = "unknown") -> str:
29-
"""Run a command and return stdout, or default on failure."""
29+
def run_cmd(cmd: List[str], default: str = "unknown") -> str:
30+
"""Execute a shell command and return its stdout output.
31+
32+
Runs the specified command as a subprocess, capturing its output.
33+
Returns the default value if the command fails or the executable
34+
is not found, making it safe to use for optional system information
35+
gathering.
36+
37+
Args:
38+
cmd: The command to execute as a list of strings, where the first
39+
element is the executable and subsequent elements are arguments.
40+
Example: ['uname', '-srm'] or ['python3', '--version'].
41+
default: The value to return if the command fails or the executable
42+
is not found. Defaults to "unknown".
43+
44+
Returns:
45+
The stripped stdout output of the command on success, or the
46+
default value if the command returns a non-zero exit code or
47+
the executable is not found.
48+
49+
Examples:
50+
>>> run_cmd(['uname', '-s'])
51+
'Linux'
52+
>>> run_cmd(['nonexistent-command'], default='N/A')
53+
'N/A'
54+
>>> run_cmd(['python3', '--version'])
55+
'Python 3.12.0'
56+
"""
3057
try:
3158
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
3259
return result.stdout.strip()

src/ab_cli/commands/resolve_conflict.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import subprocess
1010
import sys
11-
from typing import Optional
11+
from typing import Dict, List, Optional, Tuple
1212

1313
from ab_cli.core.config import get_language
1414
from ab_cli.utils import (
@@ -32,8 +32,50 @@ def has_conflict_markers(content: str) -> bool:
3232
return '<<<<<<<' in content and '=======' in content and '>>>>>>>' in content
3333

3434

35-
def parse_conflicts(content: str) -> list[dict]:
36-
"""Parse conflict sections from file content."""
35+
def parse_conflicts(content: str) -> List[Dict]:
36+
"""Parse git merge conflict sections from file content.
37+
38+
Scans the file content for git conflict markers and extracts each
39+
conflict block into a structured dictionary containing both versions
40+
of the conflicting code and their locations.
41+
42+
Conflict markers follow the standard git format:
43+
<<<<<<< HEAD (or branch name)
44+
... our version ...
45+
=======
46+
... their version ...
47+
>>>>>>> branch-name
48+
49+
Args:
50+
content: The full file content as a string, potentially containing
51+
one or more merge conflicts with standard git conflict markers.
52+
53+
Returns:
54+
A list of dictionaries, one per conflict found. Each dictionary
55+
contains:
56+
- 'start_line' (int): 1-indexed line number of the "<<<<<<" marker
57+
- 'ours_marker' (str): The full "<<<<<<" line including branch name
58+
- 'ours' (list[str]): Lines from our version (between <<<< and ====)
59+
- 'theirs' (list[str]): Lines from their version (between ==== and >>>>)
60+
- 'theirs_marker' (str): The full ">>>>>>>" line including branch name
61+
- 'end_line' (int): 1-indexed line number of the ">>>>>>>" marker
62+
63+
Returns an empty list if no conflicts are found.
64+
65+
Examples:
66+
>>> content = '''<<<<<<< HEAD
67+
... x = 1
68+
... =======
69+
... x = 2
70+
... >>>>>>> feature'''
71+
>>> conflicts = parse_conflicts(content)
72+
>>> len(conflicts)
73+
1
74+
>>> conflicts[0]['ours']
75+
['x = 1']
76+
>>> conflicts[0]['theirs']
77+
['x = 2']
78+
"""
3779
conflicts = []
3880
lines = content.split('\n')
3981

@@ -75,7 +117,7 @@ def parse_conflicts(content: str) -> list[dict]:
75117
return conflicts
76118

77119

78-
def get_file_context(filepath: str, conflict: dict, context_lines: int = 10) -> tuple[str, str]:
120+
def get_file_context(filepath: str, conflict: Dict, context_lines: int = 10) -> Tuple[str, str]:
79121
"""Get context before and after the conflict."""
80122
try:
81123
with open(filepath, 'r') as f:

src/ab_cli/utils/llm_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Provides simplified interface for LLM API calls with automatic
44
model selection based on token count.
55
"""
6-
from typing import Optional
6+
from typing import Dict, Optional, Tuple
77

88
from ab_cli.core.config import get_config, estimate_tokens
99
from ab_cli.commands.prompt import send_to_openrouter
@@ -61,7 +61,7 @@ def call_llm_with_model_info(
6161
lang: str = "en",
6262
specialist: Optional[str] = None,
6363
max_completion_tokens: int = -1,
64-
) -> tuple[Optional[dict], str, int]:
64+
) -> Tuple[Optional[Dict], str, int]:
6565
"""Call LLM and return response with model info.
6666
6767
Same as call_llm but also returns the selected model name

0 commit comments

Comments
 (0)