Skip to content

Commit

Permalink
A few more type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed May 22, 2024
1 parent 03992e1 commit db04875
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/cwhy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ def _print_message(self, message: Optional[str], file: Any = None) -> None:

class CWhyArgumentFormatter(argparse.HelpFormatter):
# RawDescriptionHelpFormatter.
def _fill_text(self, text, width, indent):
def _fill_text(self, text, width, indent): # type: ignore
return "".join(indent + line for line in text.splitlines(keepends=True))

# RawTextHelpFormatter.
def _split_lines(self, text, width):
def _split_lines(self, text, width): # type: ignore
return text.splitlines()

# ArgumentDefaultsHelpFormatter.
# Ignore if help message is multiline.
def _get_help_string(self, action):
def _get_help_string(self, action): # type: ignore
help = action.help
if "\n" not in help and "%(default)" not in action.help:
if action.default is not argparse.SUPPRESS:
Expand Down
9 changes: 6 additions & 3 deletions src/cwhy/cwhy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import sys
from typing import Any
import warnings

with warnings.catch_warnings():
Expand Down Expand Up @@ -56,7 +57,7 @@ def print_key_info() -> None:
sys.exit(1)


def complete(args, user_prompt, **kwargs):
def complete(args: argparse.Namespace, user_prompt: str, **kwargs: Any):
try:
completion = litellm.completion(
model=args.llm,
Expand Down Expand Up @@ -198,13 +199,15 @@ def main(args: argparse.Namespace) -> None:
sys.exit(process.returncode)


def evaluate_text_prompt(args, prompt, wrap=True, **kwargs):
def evaluate_text_prompt(
args: argparse.Namespace, prompt: str, wrap: bool = True, **kwargs: Any
) -> str:
completion = complete(args, prompt, **kwargs)

msg = f"Analysis from {args.llm}:"
dprint(msg)
dprint("-" * len(msg))
text = completion.choices[0].message.content
text: str = completion.choices[0].message.content

if wrap:
text = llm_utils.word_wrap_except_code_blocks(text)
Expand Down
2 changes: 1 addition & 1 deletion tests/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ROOT = os.path.dirname(os.path.abspath(__file__))


def prepare(language) -> None:
def prepare(language: str) -> None:
try:
with open(os.path.join(ROOT, language, "manifest.yml"), "r") as stream:
manifest = yaml.load(stream, yaml.Loader)
Expand Down
4 changes: 2 additions & 2 deletions tests/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ROOT = os.path.dirname(os.path.abspath(__file__))


def get_cwhy_prompt(invocation) -> str:
def get_cwhy_prompt(invocation: str) -> str:
process = subprocess.run(
f"cwhy --show-prompt --- {invocation}",
text=True,
Expand All @@ -28,7 +28,7 @@ def get_cwhy_prompt(invocation) -> str:
return stdout


def main(args) -> None:
def main(args: argparse.Namespace) -> None:
prepare.clean()
prepare.prepare_all()

Expand Down

0 comments on commit db04875

Please sign in to comment.