Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create simple_utils.py#72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
HammerHam wants to merge3 commits intocoderabbitai:main
base:main
Choose a base branch
Loading
fromHammerHam:add-utils
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletionssimple_utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
# simple_utils.py - A tiny utility libraryq

def reverse_string(text):
"""Reverses the characters in a string."""
return text[::-1]
Comment on lines +3 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

Add input validation and improve documentation.

The implementation is correct and Pythonic, but consider adding input validation to handle edge cases likeNone values or non-string types.

 def reverse_string(text):-    """Reverses the characters in a string."""+    """Reverses the characters in a string.++    Args:+        text (str): The string to reverse.++    Returns:+        str: The reversed string.++    Example:+        >>> reverse_string("hello")+        'olleh'+    """+    if text is None:+        raise ValueError("Input cannot be None")+    if not isinstance(text, str):+        raise TypeError("Input must be a string")     return text[::-1]
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defreverse_string(text):
"""Reverses the characters in a string."""
returntext[::-1]
defreverse_string(text):
"""Reversesthecharactersinastring.
Args:
text (str):Thestringtoreverse.
Returns:
str:Thereversedstring.
Example:
>>>reverse_string("hello")
'olleh'
"""
iftextisNone:
raiseValueError("Input cannot be None")
ifnotisinstance(text,str):
raiseTypeError("Input must be a string")
returntext[::-1]
🤖 Prompt for AI Agents
In simple_utils.py around lines 3 to 5, the reverse_string function lacks inputvalidation and detailed documentation. Add a type check at the start of thefunction to ensure the input is a string and raise a TypeError if not. Also,update the docstring to specify the expected input type and mention that aTypeError will be raised for invalid inputs.


def count_words(sentence):
return len(sentence.split())
Comment on lines +7 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

Add documentation and input validation.

The function lacks documentation and input validation. Consider the following improvements:

 def count_words(sentence):+    """Counts the number of words in a given text.++    Args:+        sentence (str): The text to count words in.++    Returns:+        int: The number of words found.++    Example:+        >>> count_words("Hello world")+        2+        >>> count_words("  multiple   spaces  ")+        2+    """+    if sentence is None:+        raise ValueError("Input cannot be None")+    if not isinstance(sentence, str):+        raise TypeError("Input must be a string")     return len(sentence.split())
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defcount_words(sentence):
returnlen(sentence.split())
defcount_words(sentence):
"""Countsthenumberofwordsinagiventext.
Args:
sentence (str):Thetexttocountwordsin.
Returns:
int:Thenumberofwordsfound.
Example:
>>>count_words("Hello world")
2
>>>count_words(" multiple spaces ")
2
"""
ifsentenceisNone:
raiseValueError("Input cannot be None")
ifnotisinstance(sentence,str):
raiseTypeError("Input must be a string")
returnlen(sentence.split())
🤖 Prompt for AI Agents
In simple_utils.py around lines 7 to 8, the count_words function lacks adocstring and input validation. Add a clear docstring explaining the function'spurpose, parameters, and return value. Also, include input validation to checkthat the sentence argument is a string and raise a TypeError if not.


def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
Comment on lines +10 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

Add documentation, input validation, and type hints.

The conversion formula is mathematically correct, but the function needs documentation and input validation for robustness.

-def celsius_to_fahrenheit(celsius):+def celsius_to_fahrenheit(celsius: float) -> float:+    """Converts temperature from Celsius to Fahrenheit.++    Args:+        celsius (float): Temperature in Celsius.++    Returns:+        float: Temperature in Fahrenheit.++    Example:+        >>> celsius_to_fahrenheit(0)+        32.0+        >>> celsius_to_fahrenheit(100)+        212.0+    """+    if celsius is None:+        raise ValueError("Input cannot be None")+    if not isinstance(celsius, (int, float)):+        raise TypeError("Input must be a number")     return (celsius * 9/5) + 32
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defcelsius_to_fahrenheit(celsius):
return (celsius*9/5)+32
defcelsius_to_fahrenheit(celsius:float)->float:
"""ConvertstemperaturefromCelsiustoFahrenheit.
Args:
celsius (float):TemperatureinCelsius.
Returns:
float:TemperatureinFahrenheit.
Example:
>>>celsius_to_fahrenheit(0)
32.0
>>>celsius_to_fahrenheit(100)
212.0
"""
ifcelsiusisNone:
raiseValueError("Input cannot be None")
ifnotisinstance(celsius, (int,float)):
raiseTypeError("Input must be a number")
return (celsius*9/5)+32
🤖 Prompt for AI Agents
In simple_utils.py around lines 10 to 11, the function celsius_to_fahrenheitlacks documentation, input validation, and type hints. Add a docstringexplaining the function's purpose, input parameter, and return value. Includetype hints for the input parameter and return type. Add input validation tocheck that the input is a number (int or float) and raise a TypeError if not.

1 change: 1 addition & 0 deletionstester.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@


[8]ページ先頭

©2009-2025 Movatter.jp