Skip to content

Commit

Permalink
Add some type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed May 22, 2024
1 parent 7ed8395 commit bd67121
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cwhy/cwhy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .print_debug import dprint, enable_debug_printing


def print_key_info():
def print_key_info() -> None:
dprint("You need a key (or keys) from an AI service to use CWhy.")
dprint()
dprint("OpenAI:")
Expand Down
7 changes: 5 additions & 2 deletions src/cwhy/print_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
_INFO_WIDTH = 30


def dprint(*objects, sep=" ", end="\n", file=None, flush=False):
def dprint(
*objects, sep: str = " ", end: str = "\n", file=None, flush: bool = False
) -> None:
global _debug
if not _debug:
return print(*objects, sep=sep, end=end, file=file, flush=flush)

Expand All @@ -25,6 +28,6 @@ def dprint(*objects, sep=" ", end="\n", file=None, flush=False):
print(info, line, file=file, flush=flush)


def enable_debug_printing():
def enable_debug_printing() -> None:
global _debug
_debug = True
3 changes: 2 additions & 1 deletion tests/anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import argparse
import tempfile
from typing import Tuple


def anonymize(path):
def anonymize(path: str) -> Tuple[str, str]:
with open(path) as file:
content = file.read()

Expand Down
2 changes: 1 addition & 1 deletion tests/apply_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys


def apply(data):
def apply(data) -> None:
# Sort modifications by reverse start line number to apply them in that order.
data["modifications"].sort(key=lambda m: m["start-line-number"], reverse=True)

Expand Down
6 changes: 3 additions & 3 deletions 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):
def prepare(language) -> None:
try:
with open(os.path.join(ROOT, language, "manifest.yml"), "r") as stream:
manifest = yaml.load(stream, yaml.Loader)
Expand All @@ -26,11 +26,11 @@ def prepare(language):
subprocess.run(command, shell=True).check_returncode()


def prepare_all():
def prepare_all() -> None:
for directory in os.listdir(ROOT):
if os.path.isdir(os.path.join(ROOT, directory)):
prepare(directory)


def clean():
def clean() -> None:
shutil.rmtree(os.path.join(ROOT, "_deps"), ignore_errors=True)
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):
def get_cwhy_prompt(invocation) -> str:
process = subprocess.run(
f"cwhy --show-prompt --- {invocation}",
text=True,
Expand All @@ -28,7 +28,7 @@ def get_cwhy_prompt(invocation):
return stdout


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

Expand Down

0 comments on commit bd67121

Please sign in to comment.