Skip to main content
ZhimaYuandi

F02 · PREDICT · DEBUG · VERIFY LOCALLY

F02 Preview Updates: Why Did the Original Change?

Edit a preview title and append a tag: the original changes before confirmation. Do two names really mean two records?

Back to the practice route →

The bug and the local contract

def preview_update(document, patch):
    preview = document.copy()
    preview.update(patch)
    return preview
  • Implement preview_update(document, patch). Return a new record with the same ID, allowing title, category and tags changes only. Preserve the original record and tags.
  • Editing preview tags after return must not change the original. Two previews must not share mutable tags. Invalid patches fail explicitly without partial changes.
  • Node names are not CPython addresses. C parameters, including pointers, are passed by value; changing pointed-to data differs from reassigning a local pointer.

Use fictional document metadata. The web model does not execute arbitrary code.

01 · CONTROLLED MODEL

Predict, then inspect each step

This models only the selected preset. It does not execute your Python draft or read/write computer files. One matching case does not establish correctness for all inputs.

Checks the return value, stable ID, unchanged original, post-return tag independence and two-preview independence; no real memory addresses are shown.

Unchecked or invalidated

    Before

    {
      "original": {
        "id": "doc_00000000000000000000000000000001",
        "title": "Original",
        "category": "course",
        "tags": [
          "study"
        ]
      },
      "request": {
        "title": "Preview",
        "tag": "preview"
      }
    }

    Model result

    Step through the trace to reveal the result

    Progressive learning hints

    Hints are fixed teaching content. Their use is recorded.

    Hint 1

    Compare the record before and after the call and its return value. Does an unchanged title prove independent tags?

    Hint 2

    dict.copy() copies the outer dictionary only. Tags may still be the same list. Append a tag to the preview and observe.

    Hint 3

    Copy tags for this contract and return the new record. Verify two calls and a post-return append. Rebinding a local name does not automatically return it.

    My Python draft

    Save and export your draft here. Code is not executed or synced to the starter. Draft, input or strategy edits invalidate earlier model results and self-reports.

    Local learning records

    Saved only in this browser; export is available. No cross-device sync or proof of mastery. Earlier F01 and six-task records are preserved through migration.

    • F02 opened: —
    • Model check: Unchecked or invalidated
    • Local tests (self-reported): —
    • Highest hint level: 0/3
    • Reference viewed: —
    • Unaided variant (self-reported): —

    02 · Repair your local project

    Start any task independently: its package contains that task’s bug and a runnable baseline for the other business functions. Python 3.11+, standard library only. See the package’s verification notes for tested environments.

    Download this task’s starter

    1. Extract into a new directory. Open a terminal and identify the file being run. Run public tests to reproduce the bug; consult the package’s intentional-failure list.
    2. Write a hypothesis and choose a value to inspect. Repair the specified function, retain public tests and record the diff and a minimal counterexample.
    3. Run this task’s tests, then the full regression suite. Web-model results do not replace local execution; self-reports are not remotely verified by this site.
    python check_environment.py
    python -m unittest tests.test_f02 -v
    python -m unittest discover -s tests -v

    03 · Independent variant

    Independently implement copy_schedule(schedule) in challenges.py, returning a timetable copy that preserves course IDs. Editing copied tags must not affect the original or a second copy. Supply a counterexample to shallow copying; no steps are given.

    python -m unittest tests.test_variants -v

    Implement from the requirement, replace the skipped placeholder in tests/test_student_counterexamples.py and add an assertion that exposes the original bug. Explain the failure. Hint or reference use excludes an unaided completion record for this attempt.

    Reference explanation and answer

    Try your own repair first. Opening or downloading the reference records answer use. Passing reference tests establishes only that the materials run.

    View reference explanation (records answer use)

    Assignment copies a reference. Mutating the shared dictionary changes the original. Shallow copies separate titles but not tags. Copying tags and returning a record satisfies this contract; revisit the boundary when adding nested fields.

    Download this task’s reference (answer) · Version and source digest

    Course references and review