Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I make a bug report for a small Python function reproducible?

Quick answer

Include the exact function call and inputs, what you expected, what happened instead, and the complete relevant traceback. Reduce the code and data to the smallest example that still shows the problem, then check that it runs as written in a fresh Python session. State your Python version if you know it, and remove unrelated code or private data.

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

What should I include in a bug report for a small Python function?

Geez

Make it possible for someone else to run the same case without guessing. Include:

  1. The smallest relevant function and any necessary imports.
  2. The exact call, with concrete input values.
  3. The expected result and the actual result.
  4. The full relevant traceback if Python raises an exception.
  5. The Python version and any important setup, if known.

Keep the report focused on one problem. If the function depends on other code, replace that dependency with a small example where possible. Say explicitly if you have not checked the example in a fresh session; don't imply it has been verified when it hasn't.

Follow-up question

How do I make the example small without removing the cause of the bug?

Geez

Start with the failing call and remove pieces one at a time: unrelated functions, extra input items, and setup that does not affect the result. After each removal, check whether the same unexpected behavior remains. Stop when removing anything else makes the problem disappear.

For example, if a function fails only when given an empty list, report that exact input rather than a large list of ordinary cases. Include any setup that is truly needed to reproduce the issue. If you cannot isolate it, share the smallest version you have and identify which parts you are unsure about.

Follow-up question

Can you show me a copyable format with expected and actual behavior?

Geez

Use this template and replace the bracketed parts. The example is only a format; its function and values are placeholders, not a claim about a real bug.

Title: [short description of the unexpected behavior]

Python version: [version, if known]

Code:
[smallest relevant function and imports]

Call:
[exact function call with concrete inputs]

Expected:
[what you thought the call would return or do]

Actual:
[what it returned or did instead]

Traceback:
[paste the complete relevant traceback, or write "No exception"]

Notes:
[only setup or context needed to reproduce the result]

Keep expected and actual behavior separate and specific. For instance, “expected a list containing the input; got an empty list” is easier to compare than “the function is broken.”

Follow-up question

What if I don't get an exception, or I'm not sure what part matters?

Geez

A bug can produce a result you did not expect without raising an exception. In that case, show the exact call and result; write “No exception” in the traceback field. If you are unsure which detail matters, state what you tried and what changed, rather than filling the report with guesses.

Before posting, run the example as written in a clean session if you can. Check that the inputs are included, the output matches your description, and the traceback has not been shortened in a way that hides the relevant error. Remove secrets or personal data, replacing them with clearly labeled placeholders. If the report still relies on unavailable files or setup, explain that limitation so readers know what they cannot reproduce.

A practical checklist

  • Show the smallest function and imports that still demonstrate the issue.

  • Include the exact call and concrete input values.

  • Describe expected and actual behavior separately.

  • Paste the relevant complete traceback, or state that no exception occurred.

  • Add the Python version and essential setup if known.

  • Rerun the example as written and replace private values with placeholders.

A few more useful answers

Should I include the entire program?

Usually not. Include only the code and setup needed to reproduce the function-level problem; explain if you cannot yet reduce it further.

What if I don't know my Python version?

Don't guess. Leave it as unknown or say you haven't checked; include it later if you can find it.

Do I need a traceback for every bug report?

No. Include one when an exception occurs. For an unexpected return value or behavior, report the exact call and what happened instead.

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work