-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
Here's a simple program that you could use to raise an issue, along with an example of what that issue might look like. This is a common practice for demonstrating a bug or a problem with a library.
The Program: A Simple Python Script
This program is a small, self-contained example that demonstrates a potential bug in a hypothetical library called simple_math. Let's imagine the library's add() function is supposed to handle both integers and strings, but it fails to do so correctly.
File: bug_report.py
Python
A simple script to reproduce a bug in the hypothetical 'simple_math' library
import simple_math
--- Test Case 1: Expected behavior with integers ---
try:
result_int = simple_math.add(5, 10)
print(f"Test 1 (Integers): Passed. Result is {result_int}")
assert result_int == 15
except AssertionError:
print(f"Test 1 (Integers): Failed.")
--- Test Case 2: Expected behavior with a string and an integer ---
try:
result_mixed = simple_math.add("5", 10)
print(f"Test 2 (Mixed Types): Trying to add a string and an integer...")
# This is where the bug occurs. We expect an error or a specific result.
# Let's assume the library should raise a TypeError or handle it gracefully.
print(f"Test 2 (Mixed Types): Unexpectedly succeeded. Result is {result_mixed}")
assert isinstance(result_mixed, (int, float))
except TypeError:
print(f"Test 2 (Mixed Types): Passed. Caught expected TypeError.")
except Exception as e:
print(f"Test 2 (Mixed Types): Failed. Caught unexpected exception: {e}")
The GitHub Issue
Now, you would take this program and create a new issue in the simple_math library's GitHub repository.
Issue Title:
BUG: simple_math.add() fails to handle mixed string and integer types
Issue Description:
Description of the bug
The simple_math.add() function does not correctly handle the addition of a string and an integer. Instead of raising a TypeError as expected, it appears to concatenate the values, leading to incorrect program behavior.
To Reproduce
Steps to reproduce the behavior:
Install the library: pip install simple_math
Create a file named bug_report.py with the following code:
Python
[Paste the code from bug_report.py here]
Run the script: python bug_report.py
Expected behavior
The simple_math.add("5", 10) call should raise a TypeError to prevent incorrect calculations.
Actual behavior
The call successfully executes and returns the string '510'.
Environment
OS: [e.g., Ubuntu 22.04, Windows 11]
Python Version: [e.g., 3.10.5]
simple_math library version: [e.g., 1.2.3]
Additional context
This issue was discovered while building a program that processes user input, which can sometimes be in string format. Handling the mixed types gracefully or raising an error would prevent unexpected results in user applications.
This is a great example of a simple, effective issue report because it provides:
A clear and concise title.
A "to the point" description of the problem.
A self-contained, reproducible code snippet.
The expected vs. actual behavior.
Relevant environment details.