Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

18 demos (primarily LeetCode problems) returned output strings instead of printing them. The run_demo() function only captured stdout, so these demos appeared to produce no output in the UI.

Changes

flask_app/app.py

  • Modified run_demo() to capture both stdout and return values
  • Falls back to return value when stdout is empty
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
    result = demo_fn()

output = buf.getvalue()
if not output and result is not None:
    output = str(result)

flask_app/templates/demo.html

  • Changed template condition from {% if output %} to {% if output is not none %}
  • Distinguishes between empty string (show message) and None (show nothing)

Impact

Fixes output display for 18 demos across:

  • interview_workbook.leetcode.binary_search/* (7 demos)
  • interview_workbook.leetcode.linked_list/* (2 demos)
  • interview_workbook.leetcode.two_pointers/* (8 demos)
  • interview_workbook.leetcode._audit

Screenshot

Demo output now displays correctly

"Add Two Numbers" demo now shows output "243 + 564 -> 7->0->8" instead of "no output"

Original prompt

This section details on the original issue you should resolve

<issue_title>When you click run there are a number of demos that show "no output"</issue_title>
<issue_description>When you click run there are a number of demos that show "no output"</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 19, 2025
…ions

Co-authored-by: ianlintner <500914+ianlintner@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix demos displaying no output when run Fix demos showing "no output" by capturing return values from demo functions Nov 19, 2025
Copilot AI requested a review from ianlintner November 19, 2025 23:35
@ianlintner ianlintner marked this pull request as ready for review November 19, 2025 23:47
Copilot AI review requested due to automatic review settings November 19, 2025 23:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where 18 demos (primarily LeetCode problems) were returning output strings instead of printing them, causing the UI to display "no output" because run_demo() only captured stdout.

Key Changes:

  • Modified run_demo() to capture and use return values when stdout is empty
  • Updated the demo template to distinguish between "not run" (None), "run with no output" (empty string), and "run with output" (non-empty string)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
flask_app/app.py Enhanced run_demo() to capture both stdout and return values, falling back to return value conversion when stdout is empty
flask_app/templates/demo.html Updated output section to use is not none check and display appropriate messages for empty vs. no output scenarios

After thorough review of the changed code, I found no issues within the modified regions. The implementation correctly:

  • Captures both stdout and return values from demo functions
  • Prioritizes stdout over return values (as intended by design)
  • Properly handles edge cases like falsy return values (0, False, empty collections)
  • Uses appropriate template logic to distinguish between different output states

The changes successfully address the reported issue and follow sound engineering practices.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ianlintner ianlintner merged commit 5a1c2a1 into main Nov 20, 2025
18 checks passed
@ianlintner ianlintner deleted the copilot/fix-no-output-in-demos branch November 20, 2025 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When you click run there are a number of demos that show "no output"

2 participants