From 1cb6619623e83fedfa2193c96726bff8a57ee5a1 Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:26:40 +0530 Subject: [PATCH 1/8] Add docstrings to CLI parser functions Added docstrings to build_parser and main functions for better clarity. --- fixit/cli.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fixit/cli.py b/fixit/cli.py index b5ecd6d..d842e19 100644 --- a/fixit/cli.py +++ b/fixit/cli.py @@ -14,6 +14,13 @@ def build_parser() -> argparse.ArgumentParser: + """Build the argument parser for the fixit command-line interface. + + Example: + parser = build_parser() + args = parser.parse_args(["wc", "hello world"]) + assert args.command == "wc" + """ parser = argparse.ArgumentParser(prog="fixit", description="A tiny toolbox to practice open source.") parser.add_argument("--version", action="version", version=f"fixit {__version__}") sub = parser.add_subparsers(dest="command", required=True) @@ -44,6 +51,12 @@ def build_parser() -> argparse.ArgumentParser: def main(argv=None) -> int: + """Run a fixit command and return its exit status. + + Example: + exit_code = main(["convert", "100", "c2f"]) + assert exit_code == 0 + """ try: args = build_parser().parse_args(argv) if args.command == "wc": From b19dac44400d07c5a42faad20334d5dda35e24da Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:34:00 +0530 Subject: [PATCH 2/8] Add docstrings to temperature and distance conversion functions Added docstrings to conversion functions for clarity. --- fixit/convert.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fixit/convert.py b/fixit/convert.py index 400b081..5ca0ce0 100644 --- a/fixit/convert.py +++ b/fixit/convert.py @@ -4,16 +4,36 @@ def celsius_to_fahrenheit(c: float) -> float: + """Convert a temperature from Celsius to Fahrenheit. + + Example: + celsius_to_fahrenheit(0) returns 32. + """ return c * 9 / 5 + 32 def fahrenheit_to_celsius(f: float) -> float: + """Convert a temperature from Fahrenheit to Celsius. + + Example: + fahrenheit_to_celsius(32) returns 0. + """ return (f - 32) * 5 / 9 def km_to_miles(km: float) -> float: + """Convert kilometers to miles. + + Example: + km_to_miles(1) returns approximately 0.6214. + """ return km / KM_PER_MILE def miles_to_km(miles: float) -> float: + """Convert miles to kilometers. + + Example: + miles_to_km(1) returns approximately 1.6093. + """ return miles * KM_PER_MILE From 9cb7edb45c1ad72e3b7c684bdb99a782a6c80d37 Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:38:28 +0530 Subject: [PATCH 3/8] Add docstring to format_json function Added a docstring to the format_json function to explain its purpose and provide an example usage. --- fixit/jsonfmt.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fixit/jsonfmt.py b/fixit/jsonfmt.py index 965935c..56382df 100644 --- a/fixit/jsonfmt.py +++ b/fixit/jsonfmt.py @@ -3,8 +3,12 @@ def format_json(raw: str, indent: int = 2) -> str: + """Format a JSON string with indentation. + + Example: + format_json('{"name":"Sam"}') returns '{\n "name": "Sam"\n}'. + """ try: - """Return pretty-printed JSON.""" data = json.loads(raw) return json.dumps(data, indent=indent) except json.JSONDecodeError: From cce40f3e90e50f95776cdf99156fbcbef512af2a Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:41:33 +0530 Subject: [PATCH 4/8] Enhance docstring for generate function Updated docstring to provide an example usage of the generate function. --- fixit/password.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fixit/password.py b/fixit/password.py index 7ff6e59..42621d7 100644 --- a/fixit/password.py +++ b/fixit/password.py @@ -4,7 +4,11 @@ def generate(length: int = 12, use_digits: bool = True, use_symbols: bool = False) -> str: - """Return a random password of the given length.""" + """Generate a random password of the given length. + + Example: + generate(4, use_digits=False) returns a 4-character password. + """ if length <= 0: raise ValueError("Password length must be greater then 0!") chars = string.ascii_letters From df14e7265938c7aeda1fcc07d8945144b2d986e5 Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:43:35 +0530 Subject: [PATCH 5/8] Enhance docstrings in textutils.py Updated docstrings for is_palindrome and reverse_words functions to include examples. --- fixit/textutils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fixit/textutils.py b/fixit/textutils.py index d4437c5..ce615a0 100644 --- a/fixit/textutils.py +++ b/fixit/textutils.py @@ -2,10 +2,19 @@ def is_palindrome(text: str) -> bool: - """Return True if text reads the same forwards and backwards.""" + """Check whether text reads the same forwards and backwards. + + Example: + is_palindrome("madam") returns True. + is_palindrome("hello") returns False. + """ return text == text[::-1] def reverse_words(text: str) -> str: - """Reverse the order of words in text.""" + """Reverse the order of words in text. + + Example: + reverse_words("hello world") returns "world hello". + """ return " ".join(reversed(text.split())) From d5e05222536fd4190d5cf46dfbf3e1cbf83bde36 Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:45:51 +0530 Subject: [PATCH 6/8] Enhance docstrings in wordcount.py Updated docstrings for word counting functions to provide examples and clarify their purpose. --- fixit/wordcount.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fixit/wordcount.py b/fixit/wordcount.py index 48730d1..ede6f0d 100644 --- a/fixit/wordcount.py +++ b/fixit/wordcount.py @@ -1,17 +1,33 @@ -import re """Word, line and character counting.""" +import re + def count_words(text: str) -> int: - """Return the number of words in text.""" - return len(re.split(r'\s+',text.strip())) + """Count the words in the given text. + + Example: + count_words("hello world") returns 2. + count_words("one two three") returns 3. + """ + return len(re.split(r'\s+', text.strip())) def count_lines(text: str) -> int: - """Return the number of lines in text.""" + """Count the lines in the given text. + + Example: + count_lines("hello\nworld") returns 2. + count_lines("hello") returns 1. + """ return len(text.split("\n")) def count_chars(text: str) -> int: - """Return the number of characters in text.""" + """Count the characters in the given text. + + Example: + count_chars("hello") returns 5. + count_chars("hi!") returns 3. + """ return len(text) From 6c2ead2cdda0f4c69561b8d0a5f2ce554de78cae Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:49:15 +0530 Subject: [PATCH 7/8] Fix formatting issue in __init__.py From b01579591fbc709e908f0f598fe009ca1956be02 Mon Sep 17 00:00:00 2001 From: Serena Date: Tue, 20 Oct 2026 15:56:08 +0530 Subject: [PATCH 8/8] Modify docstring example for main function Update example in main function docstring to reflect output. --- fixit/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fixit/cli.py b/fixit/cli.py index d842e19..2535721 100644 --- a/fixit/cli.py +++ b/fixit/cli.py @@ -54,8 +54,7 @@ def main(argv=None) -> int: """Run a fixit command and return its exit status. Example: - exit_code = main(["convert", "100", "c2f"]) - assert exit_code == 0 + main(["convert", "100", "c2f"]) prints 212.0 and returns 0. """ try: args = build_parser().parse_args(argv)