Skip to content

Commit 04e74b3

Browse files
Merge pull request #43 from vbossica/add_namespace_hints
Add hints for the argparse classes
2 parents c30d2fb + d359c7c commit 04e74b3

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ logging-format-style = new
66
disable = C0103,R0903,E1101,E1205,W0703
77

88
[SIMILARITIES]
9-
ignore-paths=python_gpt_po/tests
9+
ignore-paths=python_gpt_po/tests, python_gpt_po/_version.py

python_gpt_po/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import sys
1010
import traceback
11+
from argparse import Namespace
1112
from typing import Dict, List, Optional
1213

1314
from .models.config import TranslationConfig
@@ -30,7 +31,7 @@ def setup_logging():
3031
)
3132

3233

33-
def initialize_provider(args) -> tuple[ProviderClients, ModelProvider, str]:
34+
def initialize_provider(args: Namespace) -> tuple[ProviderClients, ModelProvider, str]:
3435
"""
3536
Initialize the provider client and determine the appropriate model.
3637

python_gpt_po/utils/cli.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
This module provides the argument parsing and command-line handling functionality,
44
including argument definitions, help text generation, and command processing.
55
"""
6-
import argparse
76
import logging
87
import os
98
import sys
9+
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
1010
from typing import Dict, List, Optional
1111

1212
from ..models.enums import ModelProvider, ModelProviderList
1313
from .helpers import get_version
1414

1515

16-
class CustomArgumentParser(argparse.ArgumentParser):
16+
class CustomArgumentParser(ArgumentParser):
1717
"""
1818
Custom ArgumentParser that handles errors in a more user-friendly way.
1919
"""
20-
def error(self, message):
20+
def error(self, message: str):
2121
"""
2222
Display a cleaner error message with usage information.
2323
@@ -29,12 +29,12 @@ def error(self, message):
2929
sys.exit(2)
3030

3131

32-
def parse_args():
32+
def parse_args() -> Namespace:
3333
"""
3434
Parse command-line arguments with a more user-friendly interface.
3535
3636
Returns:
37-
argparse.Namespace: Parsed arguments
37+
Namespace: Parsed arguments
3838
"""
3939
# First pass - check if list-models is in args
4040
# This allows us to make folder and lang not required when listing models
@@ -59,7 +59,7 @@ def parse_args():
5959
# Process multiple translations in bulk with a specific model
6060
gpt-po-translator --folder ./locales --lang ja,ko --bulk --model gpt-4
6161
""",
62-
formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=100)
62+
formatter_class=lambda prog: RawDescriptionHelpFormatter(prog, max_help_position=35, width=100)
6363
)
6464

6565
# Create argument groups for better organization
@@ -222,12 +222,12 @@ def create_language_mapping(lang_codes: List[str], detail_langs_arg: Optional[st
222222
return dict(zip(lang_codes, detail_langs))
223223

224224

225-
def get_provider_from_args(args) -> Optional[ModelProvider]:
225+
def get_provider_from_args(args: Namespace) -> Optional[ModelProvider]:
226226
"""
227227
Get the provider from command line arguments.
228228
229229
Args:
230-
args (argparse.Namespace): Parsed command line arguments
230+
args (Namespace): Parsed command line arguments
231231
232232
Returns:
233233
Optional[ModelProvider]: The selected provider or None if not specified
@@ -237,12 +237,12 @@ def get_provider_from_args(args) -> Optional[ModelProvider]:
237237
return None
238238

239239

240-
def get_api_keys_from_args(args) -> Dict[str, str]:
240+
def get_api_keys_from_args(args: Namespace) -> Dict[str, str]:
241241
"""
242242
Extract API keys from command line arguments and environment variables.
243243
244244
Args:
245-
args (argparse.Namespace): Parsed command line arguments
245+
args (Namespace): Parsed command line arguments
246246
247247
Returns:
248248
Dict[str, str]: Dictionary of provider names to API keys

0 commit comments

Comments
 (0)