Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Master Python pathlib.Path.copy_into in Punggol Tuition

Exterior of Singapore Institute of Technology's Punggol Campus in Singapore.

When a learner wants to put a report or project folder inside an existing archive directory, the difficult part is rarely typing copy. The difficult part is predicting the destination path, the treatment of links and metadata, and the failure that should stop the operation.

Python pathlib.Path.copy_into() was added in Python 3.14. It copies a file or directory tree into an existing target directory, handles follow_symlinks and preserve_metadata like Path.copy(), and returns a new Path pointing to the copy. Mastery begins by drawing the source, target directory and resulting child path before running code.

This guide builds that model through disposable examples, recursive trees, link policy, metadata limits, collision diagnosis, compatibility planning, explained practice and parent decisions. It never treats a pre-copy check as a guarantee against a changing filesystem.

Punggol families can use this guide in short sessions around homework, CCAs and rest. The examples are proposed learning activities. They do not claim a physical tuition branch, timetable, fee, class size, school relationship or guaranteed result.

Use disposable data and repositories, preserve backups and check version-sensitive details against the linked primary source. Current documentation settles a technical contract; observation and explanation turn that contract into usable knowledge.

Find your next learning step

Choose the route that matches the present difficulty. A complete course can follow the index in order; a repair session can begin at the first unstable distinction.

Build the model

Chapters 1–4. Model source, existing destination directory and returned path.

Read the contract

Chapters 5–8. Read file, tree, symlink and metadata rules precisely.

Test the boundary

Chapters 9–12. Test collisions, failures and changing-filesystem boundaries safely.

Diagnose and repair

Chapters 13–16. Diagnose wrong targets, permissions and version mismatches.

Transfer with judgment

Chapters 17–20. Choose copy_into, copy or shutil by the actual job.

Open the full chapter index · Jump to capstone practice · Use the How Studying Works hub · Read the primary technical source

CHAPTER 1 OF 20 · Build the model

1. The method copies into an existing directory

Back to contents

Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name. That is the invariant to preserve when names, data or surrounding project details change.

The destination child name is derived from the source name. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is predicting that notes.txt.copy_into(archive) creates archive itself or renames the file. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

from pathlib import Path
source=Path("notes.txt")
created=source.copy_into(Path("archive"))
print(created)

Explained result. The returned Path should name archive/notes.txt for a source named notes.txt. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the two input paths and the derived child path as separate states. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “The method copies into an existing directory”, separate contract from coincidence. The contract is “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Draw source, target directory and target_dir/source.name before copying.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “The method copies into an existing directory” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” should remain invariant and what observation would expose predicting that notes.txt.copy_into(archive) creates archive itself or renames the file.

Reasoned route. Begin with “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” Apply this procedure: Draw source, target directory and target_dir/source.name before copying. For the homework evidence folder, introduce one controlled variation that exposes predicting that notes.txt.copy_into(archive) creates archive itself or renames the file. The returned Path should name archive/notes.txt for a source named notes.txt. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “The method copies into an existing directory” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” should remain invariant and what observation would expose predicting that notes.txt.copy_into(archive) creates archive itself or renames the file.

Reasoned route. Begin with “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” Apply this procedure: Draw source, target directory and target_dir/source.name before copying. For the CCA media catalogue, introduce one controlled variation that exposes predicting that notes.txt.copy_into(archive) creates archive itself or renames the file. The returned Path should name archive/notes.txt for a source named notes.txt. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “The method copies into an existing directory” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” should remain invariant and what observation would expose predicting that notes.txt.copy_into(archive) creates archive itself or renames the file.

Reasoned route. Begin with “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” Apply this procedure: Draw source, target directory and target_dir/source.name before copying. For the science investigation archive, introduce one controlled variation that exposes predicting that notes.txt.copy_into(archive) creates archive itself or renames the file. The returned Path should name archive/notes.txt for a source named notes.txt. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “The method copies into an existing directory” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” should remain invariant and what observation would expose predicting that notes.txt.copy_into(archive) creates archive itself or renames the file.

Reasoned route. Begin with “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.” Apply this procedure: Draw source, target directory and target_dir/source.name before copying. For the revision-note builder, introduce one controlled variation that exposes predicting that notes.txt.copy_into(archive) creates archive itself or renames the file. The returned Path should name archive/notes.txt for a source named notes.txt. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals predicting that notes.txt.copy_into(archive) creates archive itself or renames the file.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Draw source, target directory and target_dir/source.name before copying.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “The method copies into an existing directory”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.?”, and “Can you make a smaller example of predicting that notes.txt.copy_into(archive) creates archive itself or renames the file?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Predict the result path for report.csv copied into submissions. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The result is submissions/report.csv because submissions is the container. The final output alone earns only partial credit. A strong answer connects it to “Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name.”, shows the relevant intermediate evidence and states why predicting that notes.txt.copy_into(archive) creates archive itself or renames the file would lead to a different conclusion.

Decision and transfer

Use copy_into when the container is the stable input and the source name should be retained. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “The method copies into an existing directory” means the learner can predict the ordinary case, recognise predicting that notes.txt.copy_into(archive) creates archive itself or renames the file, diagnose the earliest mistaken assumption, recover with “Draw source, target directory and target_dir/source.name before copying.” and defend this decision: Use copy_into when the container is the stable input and the source name should be retained. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 2 OF 20 · Build the model

2. The target directory should already exist

Back to contents

The documented target_dir should be an existing directory. That is the invariant to preserve when names, data or surrounding project details change.

This separates directory preparation from the copy operation. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is passing a missing nested directory and expecting copy_into to create the whole route. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

target=Path("archive")
target.mkdir()
source.copy_into(target)

Explained result. A prepared directory supports the copy; an absent or wrong-kind target should be diagnosed rather than guessed around. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace target creation before the copy call. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “The target directory should already exist”, separate contract from coincidence. The contract is “The documented target_dir should be an existing directory.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Create and verify the disposable target directory in a distinct setup step.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “The target directory should already exist” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “The documented target_dir should be an existing directory.” should remain invariant and what observation would expose passing a missing nested directory and expecting copy_into to create the whole route.

Reasoned route. Begin with “The documented target_dir should be an existing directory.” Apply this procedure: Create and verify the disposable target directory in a distinct setup step. For the homework evidence folder, introduce one controlled variation that exposes passing a missing nested directory and expecting copy_into to create the whole route. A prepared directory supports the copy; an absent or wrong-kind target should be diagnosed rather than guessed around. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “The target directory should already exist” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “The documented target_dir should be an existing directory.” should remain invariant and what observation would expose passing a missing nested directory and expecting copy_into to create the whole route.

Reasoned route. Begin with “The documented target_dir should be an existing directory.” Apply this procedure: Create and verify the disposable target directory in a distinct setup step. For the CCA media catalogue, introduce one controlled variation that exposes passing a missing nested directory and expecting copy_into to create the whole route. A prepared directory supports the copy; an absent or wrong-kind target should be diagnosed rather than guessed around. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “The target directory should already exist” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “The documented target_dir should be an existing directory.” should remain invariant and what observation would expose passing a missing nested directory and expecting copy_into to create the whole route.

Reasoned route. Begin with “The documented target_dir should be an existing directory.” Apply this procedure: Create and verify the disposable target directory in a distinct setup step. For the science investigation archive, introduce one controlled variation that exposes passing a missing nested directory and expecting copy_into to create the whole route. A prepared directory supports the copy; an absent or wrong-kind target should be diagnosed rather than guessed around. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “The target directory should already exist” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “The documented target_dir should be an existing directory.” should remain invariant and what observation would expose passing a missing nested directory and expecting copy_into to create the whole route.

Reasoned route. Begin with “The documented target_dir should be an existing directory.” Apply this procedure: Create and verify the disposable target directory in a distinct setup step. For the revision-note builder, introduce one controlled variation that exposes passing a missing nested directory and expecting copy_into to create the whole route. A prepared directory supports the copy; an absent or wrong-kind target should be diagnosed rather than guessed around. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals passing a missing nested directory and expecting copy_into to create the whole route.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Create and verify the disposable target directory in a distinct setup step.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “The target directory should already exist”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests The documented target_dir should be an existing directory.?”, and “Can you make a smaller example of passing a missing nested directory and expecting copy_into to create the whole route?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Design a test for missing, file-valued and valid directory targets. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Only the valid directory satisfies the stated precondition. The final output alone earns only partial credit. A strong answer connects it to “The documented target_dir should be an existing directory.”, shows the relevant intermediate evidence and states why passing a missing nested directory and expecting copy_into to create the whole route would lead to a different conclusion.

Decision and transfer

Prepare containers explicitly so a typo cannot silently choose a new storage location. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “The target directory should already exist” means the learner can predict the ordinary case, recognise passing a missing nested directory and expecting copy_into to create the whole route, diagnose the earliest mistaken assumption, recover with “Create and verify the disposable target directory in a distinct setup step.” and defend this decision: Prepare containers explicitly so a typo cannot silently choose a new storage location. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 3 OF 20 · Build the model

3. The return value is a new Path

Back to contents

copy_into returns a Path pointing to the copy. That is the invariant to preserve when names, data or surrounding project details change.

The caller can continue from the actual destination without rebuilding it manually. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is ignoring the return value and later joining the source name to the wrong directory. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target)
print(source)
print(copied)

Explained result. The source Path still names the source while the returned Path names the copied item. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace object values without implying that the original Path moved. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “The return value is a new Path”, separate contract from coincidence. The contract is “copy_into returns a Path pointing to the copy.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Capture the return and compare it with the expected child path.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “The return value is a new Path” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “copy_into returns a Path pointing to the copy.” should remain invariant and what observation would expose ignoring the return value and later joining the source name to the wrong directory.

Reasoned route. Begin with “copy_into returns a Path pointing to the copy.” Apply this procedure: Capture the return and compare it with the expected child path. For the homework evidence folder, introduce one controlled variation that exposes ignoring the return value and later joining the source name to the wrong directory. The source Path still names the source while the returned Path names the copied item. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “The return value is a new Path” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “copy_into returns a Path pointing to the copy.” should remain invariant and what observation would expose ignoring the return value and later joining the source name to the wrong directory.

Reasoned route. Begin with “copy_into returns a Path pointing to the copy.” Apply this procedure: Capture the return and compare it with the expected child path. For the CCA media catalogue, introduce one controlled variation that exposes ignoring the return value and later joining the source name to the wrong directory. The source Path still names the source while the returned Path names the copied item. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “The return value is a new Path” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “copy_into returns a Path pointing to the copy.” should remain invariant and what observation would expose ignoring the return value and later joining the source name to the wrong directory.

Reasoned route. Begin with “copy_into returns a Path pointing to the copy.” Apply this procedure: Capture the return and compare it with the expected child path. For the science investigation archive, introduce one controlled variation that exposes ignoring the return value and later joining the source name to the wrong directory. The source Path still names the source while the returned Path names the copied item. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “The return value is a new Path” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “copy_into returns a Path pointing to the copy.” should remain invariant and what observation would expose ignoring the return value and later joining the source name to the wrong directory.

Reasoned route. Begin with “copy_into returns a Path pointing to the copy.” Apply this procedure: Capture the return and compare it with the expected child path. For the revision-note builder, introduce one controlled variation that exposes ignoring the return value and later joining the source name to the wrong directory. The source Path still names the source while the returned Path names the copied item. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals ignoring the return value and later joining the source name to the wrong directory.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Capture the return and compare it with the expected child path.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “The return value is a new Path”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests copy_into returns a Path pointing to the copy.?”, and “Can you make a smaller example of ignoring the return value and later joining the source name to the wrong directory?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Explain why source and copied should both remain useful after the operation. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Copying preserves the source; the return identifies the new location. The final output alone earns only partial credit. A strong answer connects it to “copy_into returns a Path pointing to the copy.”, shows the relevant intermediate evidence and states why ignoring the return value and later joining the source name to the wrong directory would lead to a different conclusion.

Decision and transfer

Use the returned Path as the hand-off to later verification or processing. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “The return value is a new Path” means the learner can predict the ordinary case, recognise ignoring the return value and later joining the source name to the wrong directory, diagnose the earliest mistaken assumption, recover with “Capture the return and compare it with the expected child path.” and defend this decision: Use the returned Path as the hand-off to later verification or processing. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 4 OF 20 · Build the model

4. Files and directory trees share one entry point

Back to contents

Path.copy and copy_into can copy a file or an entire directory tree. That is the invariant to preserve when names, data or surrounding project details change.

A directory source implies recursive structure rather than one flat file. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is teaching copy_into as a file-only convenience and losing nested content. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

project=Path("project")
copy=project.copy_into(Path("backup"))
print(copy/"data"/"scores.csv")

Explained result. A directory source produces a same-named directory beneath target_dir with its descendants. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace each relative descendant under the new root. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Files and directory trees share one entry point”, separate contract from coincidence. The contract is “Path.copy and copy_into can copy a file or an entire directory tree.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Build a tiny two-level fixture and inspect the returned tree.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Files and directory trees share one entry point” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy and copy_into can copy a file or an entire directory tree.” should remain invariant and what observation would expose teaching copy_into as a file-only convenience and losing nested content.

Reasoned route. Begin with “Path.copy and copy_into can copy a file or an entire directory tree.” Apply this procedure: Build a tiny two-level fixture and inspect the returned tree. For the homework evidence folder, introduce one controlled variation that exposes teaching copy_into as a file-only convenience and losing nested content. A directory source produces a same-named directory beneath target_dir with its descendants. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Files and directory trees share one entry point” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy and copy_into can copy a file or an entire directory tree.” should remain invariant and what observation would expose teaching copy_into as a file-only convenience and losing nested content.

Reasoned route. Begin with “Path.copy and copy_into can copy a file or an entire directory tree.” Apply this procedure: Build a tiny two-level fixture and inspect the returned tree. For the CCA media catalogue, introduce one controlled variation that exposes teaching copy_into as a file-only convenience and losing nested content. A directory source produces a same-named directory beneath target_dir with its descendants. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Files and directory trees share one entry point” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy and copy_into can copy a file or an entire directory tree.” should remain invariant and what observation would expose teaching copy_into as a file-only convenience and losing nested content.

Reasoned route. Begin with “Path.copy and copy_into can copy a file or an entire directory tree.” Apply this procedure: Build a tiny two-level fixture and inspect the returned tree. For the science investigation archive, introduce one controlled variation that exposes teaching copy_into as a file-only convenience and losing nested content. A directory source produces a same-named directory beneath target_dir with its descendants. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Files and directory trees share one entry point” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy and copy_into can copy a file or an entire directory tree.” should remain invariant and what observation would expose teaching copy_into as a file-only convenience and losing nested content.

Reasoned route. Begin with “Path.copy and copy_into can copy a file or an entire directory tree.” Apply this procedure: Build a tiny two-level fixture and inspect the returned tree. For the revision-note builder, introduce one controlled variation that exposes teaching copy_into as a file-only convenience and losing nested content. A directory source produces a same-named directory beneath target_dir with its descendants. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals teaching copy_into as a file-only convenience and losing nested content.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Build a tiny two-level fixture and inspect the returned tree.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Files and directory trees share one entry point”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.copy and copy_into can copy a file or an entire directory tree.?”, and “Can you make a smaller example of teaching copy_into as a file-only convenience and losing nested content?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Predict the destination of project/data/scores.csv. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. It becomes backup/project/data/scores.csv. The final output alone earns only partial credit. A strong answer connects it to “Path.copy and copy_into can copy a file or an entire directory tree.”, shows the relevant intermediate evidence and states why teaching copy_into as a file-only convenience and losing nested content would lead to a different conclusion.

Decision and transfer

Use a tree diagram before copying a directory with several levels. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Files and directory trees share one entry point” means the learner can predict the ordinary case, recognise teaching copy_into as a file-only convenience and losing nested content, diagnose the earliest mistaken assumption, recover with “Build a tiny two-level fixture and inspect the returned tree.” and defend this decision: Use a tree diagram before copying a directory with several levels. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 5 OF 20 · Read the contract

5. Existing files can be replaced

Back to contents

Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically. That is the invariant to preserve when names, data or surrounding project details change.

Collision policy affects whether the operation is safe for schoolwork. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is assuming every collision raises FileExistsError. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

Path("in/report.txt").copy_into(Path("out"))

Explained result. A same-named destination file can be replaced by the source file. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the derived target and its prior kind before the write. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Existing files can be replaced”, separate contract from coincidence. The contract is “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Use disposable files and compare destination content before and after.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Existing files can be replaced” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” should remain invariant and what observation would expose assuming every collision raises FileExistsError.

Reasoned route. Begin with “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” Apply this procedure: Use disposable files and compare destination content before and after. For the homework evidence folder, introduce one controlled variation that exposes assuming every collision raises FileExistsError. A same-named destination file can be replaced by the source file. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Existing files can be replaced” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” should remain invariant and what observation would expose assuming every collision raises FileExistsError.

Reasoned route. Begin with “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” Apply this procedure: Use disposable files and compare destination content before and after. For the CCA media catalogue, introduce one controlled variation that exposes assuming every collision raises FileExistsError. A same-named destination file can be replaced by the source file. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Existing files can be replaced” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” should remain invariant and what observation would expose assuming every collision raises FileExistsError.

Reasoned route. Begin with “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” Apply this procedure: Use disposable files and compare destination content before and after. For the science investigation archive, introduce one controlled variation that exposes assuming every collision raises FileExistsError. A same-named destination file can be replaced by the source file. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Existing files can be replaced” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” should remain invariant and what observation would expose assuming every collision raises FileExistsError.

Reasoned route. Begin with “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.” Apply this procedure: Use disposable files and compare destination content before and after. For the revision-note builder, introduce one controlled variation that exposes assuming every collision raises FileExistsError. A same-named destination file can be replaced by the source file. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals assuming every collision raises FileExistsError.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Use disposable files and compare destination content before and after.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Existing files can be replaced”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.?”, and “Can you make a smaller example of assuming every collision raises FileExistsError?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Test a source file against an existing same-named destination file. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The file data at the destination is replaced under the documented copy rule. The final output alone earns only partial credit. A strong answer connects it to “Path.copy states that an existing file target is replaced when the source is a file, and copy_into handles arguments identically.”, shows the relevant intermediate evidence and states why assuming every collision raises FileExistsError would lead to a different conclusion.

Decision and transfer

Require backup or an explicit collision plan when replacement would be costly. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Existing files can be replaced” means the learner can predict the ordinary case, recognise assuming every collision raises FileExistsError, diagnose the earliest mistaken assumption, recover with “Use disposable files and compare destination content before and after.” and defend this decision: Require backup or an explicit collision plan when replacement would be costly. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 6 OF 20 · Read the contract

6. Directory collisions need careful diagnosis

Back to contents

A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe. That is the invariant to preserve when names, data or surrounding project details change.

Tree collisions involve more cases than one file overwrite. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is describing recursive copy as an unconditional directory merge. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

try:
    source.copy_into(target)
except OSError as exc:
    print(type(exc).__name__, exc)

Explained result. The observed failure and platform details should be reported without inventing a universal merge promise. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the first conflicting destination node. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Directory collisions need careful diagnosis”, separate contract from coincidence. The contract is “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Reproduce the exact tree in a temporary directory and catch the concrete OSError.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Directory collisions need careful diagnosis” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” should remain invariant and what observation would expose describing recursive copy as an unconditional directory merge.

Reasoned route. Begin with “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” Apply this procedure: Reproduce the exact tree in a temporary directory and catch the concrete OSError. For the homework evidence folder, introduce one controlled variation that exposes describing recursive copy as an unconditional directory merge. The observed failure and platform details should be reported without inventing a universal merge promise. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Directory collisions need careful diagnosis” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” should remain invariant and what observation would expose describing recursive copy as an unconditional directory merge.

Reasoned route. Begin with “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” Apply this procedure: Reproduce the exact tree in a temporary directory and catch the concrete OSError. For the CCA media catalogue, introduce one controlled variation that exposes describing recursive copy as an unconditional directory merge. The observed failure and platform details should be reported without inventing a universal merge promise. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Directory collisions need careful diagnosis” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” should remain invariant and what observation would expose describing recursive copy as an unconditional directory merge.

Reasoned route. Begin with “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” Apply this procedure: Reproduce the exact tree in a temporary directory and catch the concrete OSError. For the science investigation archive, introduce one controlled variation that exposes describing recursive copy as an unconditional directory merge. The observed failure and platform details should be reported without inventing a universal merge promise. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Directory collisions need careful diagnosis” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” should remain invariant and what observation would expose describing recursive copy as an unconditional directory merge.

Reasoned route. Begin with “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.” Apply this procedure: Reproduce the exact tree in a temporary directory and catch the concrete OSError. For the revision-note builder, introduce one controlled variation that exposes describing recursive copy as an unconditional directory merge. The observed failure and platform details should be reported without inventing a universal merge promise. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals describing recursive copy as an unconditional directory merge.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Reproduce the exact tree in a temporary directory and catch the concrete OSError.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Directory collisions need careful diagnosis”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.?”, and “Can you make a smaller example of describing recursive copy as an unconditional directory merge?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Create one empty and one conflicting destination tree and compare outcomes. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The conflict case must be explained from the first incompatible node. The final output alone earns only partial credit. A strong answer connects it to “A non-empty destination directory can conflict with the incoming tree and should be tested rather than assumed merge-safe.”, shows the relevant intermediate evidence and states why describing recursive copy as an unconditional directory merge would lead to a different conclusion.

Decision and transfer

Use a manifest or a fresh destination when merge semantics are not intentionally designed. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Directory collisions need careful diagnosis” means the learner can predict the ordinary case, recognise describing recursive copy as an unconditional directory merge, diagnose the earliest mistaken assumption, recover with “Reproduce the exact tree in a temporary directory and catch the concrete OSError.” and defend this decision: Use a manifest or a fresh destination when merge semantics are not intentionally designed. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

With follow_symlinks=True, a source symlink is followed and its target is copied. That is the invariant to preserve when names, data or surrounding project details change.

The copied object may differ in kind from the source directory entry. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is saying the link itself is always reproduced. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

link.copy_into(target, follow_symlinks=True)

Explained result. The default route copies the target content rather than preserving link identity. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace entry kind, target kind and destination kind. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “follow_symlinks defaults to true”, separate contract from coincidence. The contract is “With follow_symlinks=True, a source symlink is followed and its target is copied.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Draw the link and target, then label which object supplies the copied data.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “follow_symlinks defaults to true” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=True, a source symlink is followed and its target is copied.” should remain invariant and what observation would expose saying the link itself is always reproduced.

Reasoned route. Begin with “With follow_symlinks=True, a source symlink is followed and its target is copied.” Apply this procedure: Draw the link and target, then label which object supplies the copied data. For the homework evidence folder, introduce one controlled variation that exposes saying the link itself is always reproduced. The default route copies the target content rather than preserving link identity. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “follow_symlinks defaults to true” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=True, a source symlink is followed and its target is copied.” should remain invariant and what observation would expose saying the link itself is always reproduced.

Reasoned route. Begin with “With follow_symlinks=True, a source symlink is followed and its target is copied.” Apply this procedure: Draw the link and target, then label which object supplies the copied data. For the CCA media catalogue, introduce one controlled variation that exposes saying the link itself is always reproduced. The default route copies the target content rather than preserving link identity. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “follow_symlinks defaults to true” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=True, a source symlink is followed and its target is copied.” should remain invariant and what observation would expose saying the link itself is always reproduced.

Reasoned route. Begin with “With follow_symlinks=True, a source symlink is followed and its target is copied.” Apply this procedure: Draw the link and target, then label which object supplies the copied data. For the science investigation archive, introduce one controlled variation that exposes saying the link itself is always reproduced. The default route copies the target content rather than preserving link identity. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “follow_symlinks defaults to true” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=True, a source symlink is followed and its target is copied.” should remain invariant and what observation would expose saying the link itself is always reproduced.

Reasoned route. Begin with “With follow_symlinks=True, a source symlink is followed and its target is copied.” Apply this procedure: Draw the link and target, then label which object supplies the copied data. For the revision-note builder, introduce one controlled variation that exposes saying the link itself is always reproduced. The default route copies the target content rather than preserving link identity. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals saying the link itself is always reproduced.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Draw the link and target, then label which object supplies the copied data.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “follow_symlinks defaults to true”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests With follow_symlinks=True, a source symlink is followed and its target is copied.?”, and “Can you make a smaller example of saying the link itself is always reproduced?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Predict the destination when shortcut points to notes.txt. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The destination receives copied target content under the default policy. The final output alone earns only partial credit. A strong answer connects it to “With follow_symlinks=True, a source symlink is followed and its target is copied.”, shows the relevant intermediate evidence and states why saying the link itself is always reproduced would lead to a different conclusion.

Decision and transfer

Use following only when target content, not link topology, is the intended product. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “follow_symlinks defaults to true” means the learner can predict the ordinary case, recognise saying the link itself is always reproduced, diagnose the earliest mistaken assumption, recover with “Draw the link and target, then label which object supplies the copied data.” and defend this decision: Use following only when target content, not link topology, is the intended product. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

With follow_symlinks=False, a source symlink is recreated at the destination. That is the invariant to preserve when names, data or surrounding project details change.

This preserves link identity but also preserves its dependency on a target route. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is calling this a copy of the linked file data. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=link.copy_into(target, follow_symlinks=False)
print(copied.is_symlink())

Explained result. The destination is a link entry, not an independent copy of target bytes. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the link text and how it resolves from the new location. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Disabling following recreates the symlink”, separate contract from coincidence. The contract is “With follow_symlinks=False, a source symlink is recreated at the destination.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Inspect lstat or is_symlink on the destination rather than opening it first.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Disabling following recreates the symlink” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=False, a source symlink is recreated at the destination.” should remain invariant and what observation would expose calling this a copy of the linked file data.

Reasoned route. Begin with “With follow_symlinks=False, a source symlink is recreated at the destination.” Apply this procedure: Inspect lstat or is_symlink on the destination rather than opening it first. For the homework evidence folder, introduce one controlled variation that exposes calling this a copy of the linked file data. The destination is a link entry, not an independent copy of target bytes. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Disabling following recreates the symlink” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=False, a source symlink is recreated at the destination.” should remain invariant and what observation would expose calling this a copy of the linked file data.

Reasoned route. Begin with “With follow_symlinks=False, a source symlink is recreated at the destination.” Apply this procedure: Inspect lstat or is_symlink on the destination rather than opening it first. For the CCA media catalogue, introduce one controlled variation that exposes calling this a copy of the linked file data. The destination is a link entry, not an independent copy of target bytes. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Disabling following recreates the symlink” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=False, a source symlink is recreated at the destination.” should remain invariant and what observation would expose calling this a copy of the linked file data.

Reasoned route. Begin with “With follow_symlinks=False, a source symlink is recreated at the destination.” Apply this procedure: Inspect lstat or is_symlink on the destination rather than opening it first. For the science investigation archive, introduce one controlled variation that exposes calling this a copy of the linked file data. The destination is a link entry, not an independent copy of target bytes. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Disabling following recreates the symlink” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “With follow_symlinks=False, a source symlink is recreated at the destination.” should remain invariant and what observation would expose calling this a copy of the linked file data.

Reasoned route. Begin with “With follow_symlinks=False, a source symlink is recreated at the destination.” Apply this procedure: Inspect lstat or is_symlink on the destination rather than opening it first. For the revision-note builder, introduce one controlled variation that exposes calling this a copy of the linked file data. The destination is a link entry, not an independent copy of target bytes. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals calling this a copy of the linked file data.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Inspect lstat or is_symlink on the destination rather than opening it first.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Disabling following recreates the symlink”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests With follow_symlinks=False, a source symlink is recreated at the destination.?”, and “Can you make a smaller example of calling this a copy of the linked file data?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Explain how a relative link can become broken after copying. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Its stored relative target may resolve differently beneath the destination. The final output alone earns only partial credit. A strong answer connects it to “With follow_symlinks=False, a source symlink is recreated at the destination.”, shows the relevant intermediate evidence and states why calling this a copy of the linked file data would lead to a different conclusion.

Decision and transfer

Preserve links only when the destination topology makes those links meaningful. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Disabling following recreates the symlink” means the learner can predict the ordinary case, recognise calling this a copy of the linked file data, diagnose the earliest mistaken assumption, recover with “Inspect lstat or is_symlink on the destination rather than opening it first.” and defend this decision: Preserve links only when the destination topology makes those links meaningful. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 9 OF 20 · Test the boundary

9. preserve_metadata defaults to false

Back to contents

With preserve_metadata=False, only directory structures and file data are guaranteed to be copied. That is the invariant to preserve when names, data or surrounding project details change.

Permissions, flags, times and extended attributes are separate policy. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is assuming copied modification time proves preservation. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target, preserve_metadata=False)

Explained result. The bytes and tree are the guaranteed core; other metadata may differ. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace content and metadata as different verification layers. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “preserve_metadata defaults to false”, separate contract from coincidence. The contract is “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Compare data integrity separately from metadata fields.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “preserve_metadata defaults to false” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” should remain invariant and what observation would expose assuming copied modification time proves preservation.

Reasoned route. Begin with “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” Apply this procedure: Compare data integrity separately from metadata fields. For the homework evidence folder, introduce one controlled variation that exposes assuming copied modification time proves preservation. The bytes and tree are the guaranteed core; other metadata may differ. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “preserve_metadata defaults to false” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” should remain invariant and what observation would expose assuming copied modification time proves preservation.

Reasoned route. Begin with “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” Apply this procedure: Compare data integrity separately from metadata fields. For the CCA media catalogue, introduce one controlled variation that exposes assuming copied modification time proves preservation. The bytes and tree are the guaranteed core; other metadata may differ. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “preserve_metadata defaults to false” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” should remain invariant and what observation would expose assuming copied modification time proves preservation.

Reasoned route. Begin with “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” Apply this procedure: Compare data integrity separately from metadata fields. For the science investigation archive, introduce one controlled variation that exposes assuming copied modification time proves preservation. The bytes and tree are the guaranteed core; other metadata may differ. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “preserve_metadata defaults to false” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” should remain invariant and what observation would expose assuming copied modification time proves preservation.

Reasoned route. Begin with “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.” Apply this procedure: Compare data integrity separately from metadata fields. For the revision-note builder, introduce one controlled variation that exposes assuming copied modification time proves preservation. The bytes and tree are the guaranteed core; other metadata may differ. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals assuming copied modification time proves preservation.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Compare data integrity separately from metadata fields.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “preserve_metadata defaults to false”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.?”, and “Can you make a smaller example of assuming copied modification time proves preservation?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. List what a homework backup must preserve and what it merely may preserve. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. File data is central; timestamps or extended attributes require an explicit policy. The final output alone earns only partial credit. A strong answer connects it to “With preserve_metadata=False, only directory structures and file data are guaranteed to be copied.”, shows the relevant intermediate evidence and states why assuming copied modification time proves preservation would lead to a different conclusion.

Decision and transfer

Keep the default when content is the job and metadata fidelity is unnecessary. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “preserve_metadata defaults to false” means the learner can predict the ordinary case, recognise assuming copied modification time proves preservation, diagnose the earliest mistaken assumption, recover with “Compare data integrity separately from metadata fields.” and defend this decision: Keep the default when content is the job and metadata fidelity is unnecessary. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 10 OF 20 · Test the boundary

10. preserve_metadata requests richer fidelity

Back to contents

With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported. That is the invariant to preserve when names, data or surrounding project details change.

The phrase where supported prevents a cross-platform absolute promise. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is claiming identical metadata on every filesystem. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target, preserve_metadata=True)

Explained result. Supported metadata is requested, while unsupported details remain an environmental boundary. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace each checked attribute and its support assumptions. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “preserve_metadata requests richer fidelity”, separate contract from coincidence. The contract is “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Verify only the fields available and meaningful on the tested platform.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “preserve_metadata requests richer fidelity” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” should remain invariant and what observation would expose claiming identical metadata on every filesystem.

Reasoned route. Begin with “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” Apply this procedure: Verify only the fields available and meaningful on the tested platform. For the homework evidence folder, introduce one controlled variation that exposes claiming identical metadata on every filesystem. Supported metadata is requested, while unsupported details remain an environmental boundary. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “preserve_metadata requests richer fidelity” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” should remain invariant and what observation would expose claiming identical metadata on every filesystem.

Reasoned route. Begin with “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” Apply this procedure: Verify only the fields available and meaningful on the tested platform. For the CCA media catalogue, introduce one controlled variation that exposes claiming identical metadata on every filesystem. Supported metadata is requested, while unsupported details remain an environmental boundary. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “preserve_metadata requests richer fidelity” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” should remain invariant and what observation would expose claiming identical metadata on every filesystem.

Reasoned route. Begin with “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” Apply this procedure: Verify only the fields available and meaningful on the tested platform. For the science investigation archive, introduce one controlled variation that exposes claiming identical metadata on every filesystem. Supported metadata is requested, while unsupported details remain an environmental boundary. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “preserve_metadata requests richer fidelity” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” should remain invariant and what observation would expose claiming identical metadata on every filesystem.

Reasoned route. Begin with “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.” Apply this procedure: Verify only the fields available and meaningful on the tested platform. For the revision-note builder, introduce one controlled variation that exposes claiming identical metadata on every filesystem. Supported metadata is requested, while unsupported details remain an environmental boundary. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals claiming identical metadata on every filesystem.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Verify only the fields available and meaningful on the tested platform.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “preserve_metadata requests richer fidelity”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.?”, and “Can you make a smaller example of claiming identical metadata on every filesystem?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Design a metadata test that skips unavailable extended attributes honestly. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The test should distinguish unsupported from incorrectly copied. The final output alone earns only partial credit. A strong answer connects it to “With preserve_metadata=True, permissions, flags, access and modification times, and extended attributes are copied where supported.”, shows the relevant intermediate evidence and states why claiming identical metadata on every filesystem would lead to a different conclusion.

Decision and transfer

Choose true for archival fidelity after defining which metadata matters. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “preserve_metadata requests richer fidelity” means the learner can predict the ordinary case, recognise claiming identical metadata on every filesystem, diagnose the earliest mistaken assumption, recover with “Verify only the fields available and meaningful on the tested platform.” and defend this decision: Choose true for archival fidelity after defining which metadata matters. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 11 OF 20 · Test the boundary

11. Windows treats file metadata specially

Back to contents

The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there. That is the invariant to preserve when names, data or surrounding project details change.

A cross-platform lesson must not infer identical mechanisms from identical-looking results. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is using one Windows observation to describe every platform. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target, preserve_metadata=True)

Explained result. The flag does not change Windows file behaviour under this documented rule. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace policy request separately from platform implementation. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Windows treats file metadata specially”, separate contract from coincidence. The contract is “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Record operating system, object kind and checked metadata before comparing.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Windows treats file metadata specially” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” should remain invariant and what observation would expose using one Windows observation to describe every platform.

Reasoned route. Begin with “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” Apply this procedure: Record operating system, object kind and checked metadata before comparing. For the homework evidence folder, introduce one controlled variation that exposes using one Windows observation to describe every platform. The flag does not change Windows file behaviour under this documented rule. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Windows treats file metadata specially” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” should remain invariant and what observation would expose using one Windows observation to describe every platform.

Reasoned route. Begin with “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” Apply this procedure: Record operating system, object kind and checked metadata before comparing. For the CCA media catalogue, introduce one controlled variation that exposes using one Windows observation to describe every platform. The flag does not change Windows file behaviour under this documented rule. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Windows treats file metadata specially” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” should remain invariant and what observation would expose using one Windows observation to describe every platform.

Reasoned route. Begin with “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” Apply this procedure: Record operating system, object kind and checked metadata before comparing. For the science investigation archive, introduce one controlled variation that exposes using one Windows observation to describe every platform. The flag does not change Windows file behaviour under this documented rule. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Windows treats file metadata specially” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” should remain invariant and what observation would expose using one Windows observation to describe every platform.

Reasoned route. Begin with “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.” Apply this procedure: Record operating system, object kind and checked metadata before comparing. For the revision-note builder, introduce one controlled variation that exposes using one Windows observation to describe every platform. The flag does not change Windows file behaviour under this documented rule. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals using one Windows observation to describe every platform.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Record operating system, object kind and checked metadata before comparing.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Windows treats file metadata specially”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.?”, and “Can you make a smaller example of using one Windows observation to describe every platform?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Explain why toggling the flag may show no file difference on Windows. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Windows already preserves that file metadata according to the contract. The final output alone earns only partial credit. A strong answer connects it to “The documentation states preserve_metadata has no effect for files on Windows because metadata is always preserved there.”, shows the relevant intermediate evidence and states why using one Windows observation to describe every platform would lead to a different conclusion.

Decision and transfer

Write platform-aware tests instead of brittle universal timestamp assertions. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Windows treats file metadata specially” means the learner can predict the ordinary case, recognise using one Windows observation to describe every platform, diagnose the earliest mistaken assumption, recover with “Record operating system, object kind and checked metadata before comparing.” and defend this decision: Write platform-aware tests instead of brittle universal timestamp assertions. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 12 OF 20 · Test the boundary

12. Copy-on-write may be used where supported

Back to contents

Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write. That is the invariant to preserve when names, data or surrounding project details change.

This is an optimisation, not a semantic promise that source and copy share future writes. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is teaching copy-on-write as hard links or shared mutable content. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target)
copied.write_text("changed")

Explained result. Changing the copy does not redefine the source-copy contract even if blocks began shared internally. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace logical files separately from physical storage optimisation. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Copy-on-write may be used where supported”, separate contract from coincidence. The contract is “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Verify independent file behaviour and treat storage optimisation as optional.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Copy-on-write may be used where supported” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” should remain invariant and what observation would expose teaching copy-on-write as hard links or shared mutable content.

Reasoned route. Begin with “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” Apply this procedure: Verify independent file behaviour and treat storage optimisation as optional. For the homework evidence folder, introduce one controlled variation that exposes teaching copy-on-write as hard links or shared mutable content. Changing the copy does not redefine the source-copy contract even if blocks began shared internally. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Copy-on-write may be used where supported” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” should remain invariant and what observation would expose teaching copy-on-write as hard links or shared mutable content.

Reasoned route. Begin with “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” Apply this procedure: Verify independent file behaviour and treat storage optimisation as optional. For the CCA media catalogue, introduce one controlled variation that exposes teaching copy-on-write as hard links or shared mutable content. Changing the copy does not redefine the source-copy contract even if blocks began shared internally. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Copy-on-write may be used where supported” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” should remain invariant and what observation would expose teaching copy-on-write as hard links or shared mutable content.

Reasoned route. Begin with “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” Apply this procedure: Verify independent file behaviour and treat storage optimisation as optional. For the science investigation archive, introduce one controlled variation that exposes teaching copy-on-write as hard links or shared mutable content. Changing the copy does not redefine the source-copy contract even if blocks began shared internally. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Copy-on-write may be used where supported” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” should remain invariant and what observation would expose teaching copy-on-write as hard links or shared mutable content.

Reasoned route. Begin with “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.” Apply this procedure: Verify independent file behaviour and treat storage optimisation as optional. For the revision-note builder, introduce one controlled variation that exposes teaching copy-on-write as hard links or shared mutable content. Changing the copy does not redefine the source-copy contract even if blocks began shared internally. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals teaching copy-on-write as hard links or shared mutable content.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Verify independent file behaviour and treat storage optimisation as optional.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Copy-on-write may be used where supported”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.?”, and “Can you make a smaller example of teaching copy-on-write as hard links or shared mutable content?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Explain why a lightweight copy remains a copy. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The filesystem may share blocks until modification while the paths behave as distinct files. The final output alone earns only partial credit. A strong answer connects it to “Path.copy may perform a lightweight copy where the operating system and filesystem support copy-on-write.”, shows the relevant intermediate evidence and states why teaching copy-on-write as hard links or shared mutable content would lead to a different conclusion.

Decision and transfer

Never depend on copy-on-write availability for correctness. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Copy-on-write may be used where supported” means the learner can predict the ordinary case, recognise teaching copy-on-write as hard links or shared mutable content, diagnose the earliest mistaken assumption, recover with “Verify independent file behaviour and treat storage optimisation as optional.” and defend this decision: Never depend on copy-on-write availability for correctness. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 13 OF 20 · Diagnose and repair

13. Errors should preserve their concrete cause

Back to contents

copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations. That is the invariant to preserve when names, data or surrounding project details change.

A generic failed label loses the repair route. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is catching Exception and printing could not copy. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

try:
    source.copy_into(target)
except OSError as exc:
    print(type(exc).__name__, source, target, exc)

Explained result. The report distinguishes preparation, permission and collision problems. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the first filesystem operation that failed. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Errors should preserve their concrete cause”, separate contract from coincidence. The contract is “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Catch OSError at the application boundary and retain type, source, target and message.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Errors should preserve their concrete cause” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” should remain invariant and what observation would expose catching Exception and printing could not copy.

Reasoned route. Begin with “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” Apply this procedure: Catch OSError at the application boundary and retain type, source, target and message. For the homework evidence folder, introduce one controlled variation that exposes catching Exception and printing could not copy. The report distinguishes preparation, permission and collision problems. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Errors should preserve their concrete cause” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” should remain invariant and what observation would expose catching Exception and printing could not copy.

Reasoned route. Begin with “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” Apply this procedure: Catch OSError at the application boundary and retain type, source, target and message. For the CCA media catalogue, introduce one controlled variation that exposes catching Exception and printing could not copy. The report distinguishes preparation, permission and collision problems. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Errors should preserve their concrete cause” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” should remain invariant and what observation would expose catching Exception and printing could not copy.

Reasoned route. Begin with “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” Apply this procedure: Catch OSError at the application boundary and retain type, source, target and message. For the science investigation archive, introduce one controlled variation that exposes catching Exception and printing could not copy. The report distinguishes preparation, permission and collision problems. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Errors should preserve their concrete cause” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” should remain invariant and what observation would expose catching Exception and printing could not copy.

Reasoned route. Begin with “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.” Apply this procedure: Catch OSError at the application boundary and retain type, source, target and message. For the revision-note builder, introduce one controlled variation that exposes catching Exception and printing could not copy. The report distinguishes preparation, permission and collision problems. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals catching Exception and printing could not copy.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Catch OSError at the application boundary and retain type, source, target and message.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Errors should preserve their concrete cause”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.?”, and “Can you make a smaller example of catching Exception and printing could not copy?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Design three diagnostic fixtures without touching personal files. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Each failure should retain enough context for a specific correction. The final output alone earns only partial credit. A strong answer connects it to “copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations.”, shows the relevant intermediate evidence and states why catching Exception and printing could not copy would lead to a different conclusion.

Decision and transfer

Handle only recoverable causes; re-raise unexpected failures. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Errors should preserve their concrete cause” means the learner can predict the ordinary case, recognise catching Exception and printing could not copy, diagnose the earliest mistaken assumption, recover with “Catch OSError at the application boundary and retain type, source, target and message.” and defend this decision: Handle only recoverable causes; re-raise unexpected failures. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 14 OF 20 · Diagnose and repair

14. Prechecks do not freeze the filesystem

Back to contents

Checking source.exists and target.is_dir before copying cannot make later state atomic. That is the invariant to preserve when names, data or surrounding project details change.

Another process can replace either path between check and use. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is treating successful prechecks as a guarantee the copy must succeed. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

if target.is_dir():
    copied=source.copy_into(target)

Explained result. The operation may still fail or copy changed state. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace check, external change and copy as separate times. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Prechecks do not freeze the filesystem”, separate contract from coincidence. The contract is “Checking source.exists and target.is_dir before copying cannot make later state atomic.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Use prechecks for messages but handle the copy call outcome as decisive.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Prechecks do not freeze the filesystem” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Checking source.exists and target.is_dir before copying cannot make later state atomic.” should remain invariant and what observation would expose treating successful prechecks as a guarantee the copy must succeed.

Reasoned route. Begin with “Checking source.exists and target.is_dir before copying cannot make later state atomic.” Apply this procedure: Use prechecks for messages but handle the copy call outcome as decisive. For the homework evidence folder, introduce one controlled variation that exposes treating successful prechecks as a guarantee the copy must succeed. The operation may still fail or copy changed state. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Prechecks do not freeze the filesystem” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Checking source.exists and target.is_dir before copying cannot make later state atomic.” should remain invariant and what observation would expose treating successful prechecks as a guarantee the copy must succeed.

Reasoned route. Begin with “Checking source.exists and target.is_dir before copying cannot make later state atomic.” Apply this procedure: Use prechecks for messages but handle the copy call outcome as decisive. For the CCA media catalogue, introduce one controlled variation that exposes treating successful prechecks as a guarantee the copy must succeed. The operation may still fail or copy changed state. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Prechecks do not freeze the filesystem” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Checking source.exists and target.is_dir before copying cannot make later state atomic.” should remain invariant and what observation would expose treating successful prechecks as a guarantee the copy must succeed.

Reasoned route. Begin with “Checking source.exists and target.is_dir before copying cannot make later state atomic.” Apply this procedure: Use prechecks for messages but handle the copy call outcome as decisive. For the science investigation archive, introduce one controlled variation that exposes treating successful prechecks as a guarantee the copy must succeed. The operation may still fail or copy changed state. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Prechecks do not freeze the filesystem” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Checking source.exists and target.is_dir before copying cannot make later state atomic.” should remain invariant and what observation would expose treating successful prechecks as a guarantee the copy must succeed.

Reasoned route. Begin with “Checking source.exists and target.is_dir before copying cannot make later state atomic.” Apply this procedure: Use prechecks for messages but handle the copy call outcome as decisive. For the revision-note builder, introduce one controlled variation that exposes treating successful prechecks as a guarantee the copy must succeed. The operation may still fail or copy changed state. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals treating successful prechecks as a guarantee the copy must succeed.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Use prechecks for messages but handle the copy call outcome as decisive.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Prechecks do not freeze the filesystem”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Checking source.exists and target.is_dir before copying cannot make later state atomic.?”, and “Can you make a smaller example of treating successful prechecks as a guarantee the copy must succeed?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Explain the time-of-check/time-of-use gap. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Shared filesystem state can change after the check. The final output alone earns only partial credit. A strong answer connects it to “Checking source.exists and target.is_dir before copying cannot make later state atomic.”, shows the relevant intermediate evidence and states why treating successful prechecks as a guarantee the copy must succeed would lead to a different conclusion.

Decision and transfer

Do not use convenience checks as security or concurrency guarantees. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Prechecks do not freeze the filesystem” means the learner can predict the ordinary case, recognise treating successful prechecks as a guarantee the copy must succeed, diagnose the earliest mistaken assumption, recover with “Use prechecks for messages but handle the copy call outcome as decisive.” and defend this decision: Do not use convenience checks as security or concurrency guarantees. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 15 OF 20 · Diagnose and repair

15. Path.copy accepts an exact destination

Back to contents

Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination. That is the invariant to preserve when names, data or surrounding project details change.

Choosing the wrong API can add or omit a path level. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is using copy_into when the user needs a renamed output file. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

source.copy(Path("archive/final-report.txt"))

Explained result. A rename-on-copy job belongs naturally to copy; a container job belongs naturally to copy_into. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace desired destination before method selection. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Path.copy accepts an exact destination”, separate contract from coincidence. The contract is “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Write the intended final path in full before choosing.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Path.copy accepts an exact destination” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” should remain invariant and what observation would expose using copy_into when the user needs a renamed output file.

Reasoned route. Begin with “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” Apply this procedure: Write the intended final path in full before choosing. For the homework evidence folder, introduce one controlled variation that exposes using copy_into when the user needs a renamed output file. A rename-on-copy job belongs naturally to copy; a container job belongs naturally to copy_into. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Path.copy accepts an exact destination” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” should remain invariant and what observation would expose using copy_into when the user needs a renamed output file.

Reasoned route. Begin with “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” Apply this procedure: Write the intended final path in full before choosing. For the CCA media catalogue, introduce one controlled variation that exposes using copy_into when the user needs a renamed output file. A rename-on-copy job belongs naturally to copy; a container job belongs naturally to copy_into. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Path.copy accepts an exact destination” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” should remain invariant and what observation would expose using copy_into when the user needs a renamed output file.

Reasoned route. Begin with “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” Apply this procedure: Write the intended final path in full before choosing. For the science investigation archive, introduce one controlled variation that exposes using copy_into when the user needs a renamed output file. A rename-on-copy job belongs naturally to copy; a container job belongs naturally to copy_into. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Path.copy accepts an exact destination” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” should remain invariant and what observation would expose using copy_into when the user needs a renamed output file.

Reasoned route. Begin with “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.” Apply this procedure: Write the intended final path in full before choosing. For the revision-note builder, introduce one controlled variation that exposes using copy_into when the user needs a renamed output file. A rename-on-copy job belongs naturally to copy; a container job belongs naturally to copy_into. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals using copy_into when the user needs a renamed output file.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Write the intended final path in full before choosing.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Path.copy accepts an exact destination”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.?”, and “Can you make a smaller example of using copy_into when the user needs a renamed output file?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Map two jobs: keep the source name, and assign a new name. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Use copy_into for the first and copy for the second. The final output alone earns only partial credit. A strong answer connects it to “Path.copy(target) names the destination directly, while copy_into(target_dir) derives a child destination.”, shows the relevant intermediate evidence and states why using copy_into when the user needs a renamed output file would lead to a different conclusion.

Decision and transfer

Choose based on whether the final basename is input or derived. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Path.copy accepts an exact destination” means the learner can predict the ordinary case, recognise using copy_into when the user needs a renamed output file, diagnose the earliest mistaken assumption, recover with “Write the intended final path in full before choosing.” and defend this decision: Choose based on whether the final basename is input or derived. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 16 OF 20 · Diagnose and repair

16. shutil remains a compatibility and control option

Back to contents

Older Python versions use shutil.copy, copy2 or copytree for related jobs. That is the invariant to preserve when names, data or surrounding project details change.

Path.copy_into is new in Python 3.14 and is not a silent backport. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is writing fallback code that assumes identical parameters and errors. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

if hasattr(source,"copy_into"):
    copied=source.copy_into(target)

Explained result. Compatibility becomes explicit rather than failing at attribute access. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace capability detection before the copy branch. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “shutil remains a compatibility and control option”, separate contract from coincidence. The contract is “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Define the minimum Python version or test a deliberate shutil fallback.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “shutil remains a compatibility and control option” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” should remain invariant and what observation would expose writing fallback code that assumes identical parameters and errors.

Reasoned route. Begin with “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” Apply this procedure: Define the minimum Python version or test a deliberate shutil fallback. For the homework evidence folder, introduce one controlled variation that exposes writing fallback code that assumes identical parameters and errors. Compatibility becomes explicit rather than failing at attribute access. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “shutil remains a compatibility and control option” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” should remain invariant and what observation would expose writing fallback code that assumes identical parameters and errors.

Reasoned route. Begin with “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” Apply this procedure: Define the minimum Python version or test a deliberate shutil fallback. For the CCA media catalogue, introduce one controlled variation that exposes writing fallback code that assumes identical parameters and errors. Compatibility becomes explicit rather than failing at attribute access. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “shutil remains a compatibility and control option” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” should remain invariant and what observation would expose writing fallback code that assumes identical parameters and errors.

Reasoned route. Begin with “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” Apply this procedure: Define the minimum Python version or test a deliberate shutil fallback. For the science investigation archive, introduce one controlled variation that exposes writing fallback code that assumes identical parameters and errors. Compatibility becomes explicit rather than failing at attribute access. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “shutil remains a compatibility and control option” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” should remain invariant and what observation would expose writing fallback code that assumes identical parameters and errors.

Reasoned route. Begin with “Older Python versions use shutil.copy, copy2 or copytree for related jobs.” Apply this procedure: Define the minimum Python version or test a deliberate shutil fallback. For the revision-note builder, introduce one controlled variation that exposes writing fallback code that assumes identical parameters and errors. Compatibility becomes explicit rather than failing at attribute access. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals writing fallback code that assumes identical parameters and errors.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Define the minimum Python version or test a deliberate shutil fallback.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “shutil remains a compatibility and control option”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Older Python versions use shutil.copy, copy2 or copytree for related jobs.?”, and “Can you make a smaller example of writing fallback code that assumes identical parameters and errors?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Plan for a lab using Python 3.12. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Use a tested shutil route or require Python 3.14. The final output alone earns only partial credit. A strong answer connects it to “Older Python versions use shutil.copy, copy2 or copytree for related jobs.”, shows the relevant intermediate evidence and states why writing fallback code that assumes identical parameters and errors would lead to a different conclusion.

Decision and transfer

Prefer one supported policy over untested conditional complexity. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “shutil remains a compatibility and control option” means the learner can predict the ordinary case, recognise writing fallback code that assumes identical parameters and errors, diagnose the earliest mistaken assumption, recover with “Define the minimum Python version or test a deliberate shutil fallback.” and defend this decision: Prefer one supported policy over untested conditional complexity. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 17 OF 20 · Transfer with judgment

17. Relative paths depend on the working directory

Back to contents

Relative source and target paths are interpreted from the process working directory. That is the invariant to preserve when names, data or surrounding project details change.

A script launched elsewhere can copy into an unintended location. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is assuming relative target means relative to the source parent. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

root=Path.cwd()
target=(root/"archive").resolve()

Explained result. The planned absolute locations become reviewable. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace the working directory and each resolved path. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Relative paths depend on the working directory”, separate contract from coincidence. The contract is “Relative source and target paths are interpreted from the process working directory.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Resolve or anchor paths from a known project root and log them before writing.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Relative paths depend on the working directory” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Relative source and target paths are interpreted from the process working directory.” should remain invariant and what observation would expose assuming relative target means relative to the source parent.

Reasoned route. Begin with “Relative source and target paths are interpreted from the process working directory.” Apply this procedure: Resolve or anchor paths from a known project root and log them before writing. For the homework evidence folder, introduce one controlled variation that exposes assuming relative target means relative to the source parent. The planned absolute locations become reviewable. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Relative paths depend on the working directory” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Relative source and target paths are interpreted from the process working directory.” should remain invariant and what observation would expose assuming relative target means relative to the source parent.

Reasoned route. Begin with “Relative source and target paths are interpreted from the process working directory.” Apply this procedure: Resolve or anchor paths from a known project root and log them before writing. For the CCA media catalogue, introduce one controlled variation that exposes assuming relative target means relative to the source parent. The planned absolute locations become reviewable. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Relative paths depend on the working directory” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Relative source and target paths are interpreted from the process working directory.” should remain invariant and what observation would expose assuming relative target means relative to the source parent.

Reasoned route. Begin with “Relative source and target paths are interpreted from the process working directory.” Apply this procedure: Resolve or anchor paths from a known project root and log them before writing. For the science investigation archive, introduce one controlled variation that exposes assuming relative target means relative to the source parent. The planned absolute locations become reviewable. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Relative paths depend on the working directory” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Relative source and target paths are interpreted from the process working directory.” should remain invariant and what observation would expose assuming relative target means relative to the source parent.

Reasoned route. Begin with “Relative source and target paths are interpreted from the process working directory.” Apply this procedure: Resolve or anchor paths from a known project root and log them before writing. For the revision-note builder, introduce one controlled variation that exposes assuming relative target means relative to the source parent. The planned absolute locations become reviewable. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals assuming relative target means relative to the source parent.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Resolve or anchor paths from a known project root and log them before writing.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Relative paths depend on the working directory”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Relative source and target paths are interpreted from the process working directory.?”, and “Can you make a smaller example of assuming relative target means relative to the source parent?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Run a harmless planner from two working directories. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. The same relative text can resolve to different locations. The final output alone earns only partial credit. A strong answer connects it to “Relative source and target paths are interpreted from the process working directory.”, shows the relevant intermediate evidence and states why assuming relative target means relative to the source parent would lead to a different conclusion.

Decision and transfer

Use explicit project roots in automation and school workflows. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Relative paths depend on the working directory” means the learner can predict the ordinary case, recognise assuming relative target means relative to the source parent, diagnose the earliest mistaken assumption, recover with “Resolve or anchor paths from a known project root and log them before writing.” and defend this decision: Use explicit project roots in automation and school workflows. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 18 OF 20 · Transfer with judgment

18. Verification should test content and structure

Back to contents

A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs. That is the invariant to preserve when names, data or surrounding project details change.

Verification catches wrong path assumptions and incomplete fixtures. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is checking only copied.exists and ignoring tree contents. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

expected={"a.txt","data/b.csv"}
actual={str(p.relative_to(copied)) for p in copied.rglob("*") if p.is_file()}

Explained result. The check validates the copied product without claiming an atomic snapshot. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace expected and actual manifests. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Verification should test content and structure”, separate contract from coincidence. The contract is “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Compare a small manifest of relative paths and selected hashes.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Verification should test content and structure” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” should remain invariant and what observation would expose checking only copied.exists and ignoring tree contents.

Reasoned route. Begin with “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” Apply this procedure: Compare a small manifest of relative paths and selected hashes. For the homework evidence folder, introduce one controlled variation that exposes checking only copied.exists and ignoring tree contents. The check validates the copied product without claiming an atomic snapshot. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Verification should test content and structure” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” should remain invariant and what observation would expose checking only copied.exists and ignoring tree contents.

Reasoned route. Begin with “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” Apply this procedure: Compare a small manifest of relative paths and selected hashes. For the CCA media catalogue, introduce one controlled variation that exposes checking only copied.exists and ignoring tree contents. The check validates the copied product without claiming an atomic snapshot. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Verification should test content and structure” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” should remain invariant and what observation would expose checking only copied.exists and ignoring tree contents.

Reasoned route. Begin with “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” Apply this procedure: Compare a small manifest of relative paths and selected hashes. For the science investigation archive, introduce one controlled variation that exposes checking only copied.exists and ignoring tree contents. The check validates the copied product without claiming an atomic snapshot. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Verification should test content and structure” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” should remain invariant and what observation would expose checking only copied.exists and ignoring tree contents.

Reasoned route. Begin with “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.” Apply this procedure: Compare a small manifest of relative paths and selected hashes. For the revision-note builder, introduce one controlled variation that exposes checking only copied.exists and ignoring tree contents. The check validates the copied product without claiming an atomic snapshot. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals checking only copied.exists and ignoring tree contents.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Compare a small manifest of relative paths and selected hashes.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Verification should test content and structure”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.?”, and “Can you make a smaller example of checking only copied.exists and ignoring tree contents?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Build a two-file tree and explain any extra or missing entry. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Set comparison reveals structural differences; hashes can test chosen file data. The final output alone earns only partial credit. A strong answer connects it to “A successful return means the operation completed, but a robust exercise verifies the properties the job actually needs.”, shows the relevant intermediate evidence and states why checking only copied.exists and ignoring tree contents would lead to a different conclusion.

Decision and transfer

Scale verification to risk instead of rereading huge trees blindly. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Verification should test content and structure” means the learner can predict the ordinary case, recognise checking only copied.exists and ignoring tree contents, diagnose the earliest mistaken assumption, recover with “Compare a small manifest of relative paths and selected hashes.” and defend this decision: Scale verification to risk instead of rereading huge trees blindly. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 19 OF 20 · Transfer with judgment

19. Tests belong in temporary directories

Back to contents

Copy tests should use isolated disposable fixtures rather than live homework folders. That is the invariant to preserve when names, data or surrounding project details change.

Isolation makes collisions, links and failures reproducible. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is experimenting inside Documents and hoping cleanup is correct. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

from tempfile import TemporaryDirectory
with TemporaryDirectory() as d:
    root=Path(d)

Explained result. The test can be repeated without endangering personal data. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace fixture creation, action and automatic cleanup. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Tests belong in temporary directories”, separate contract from coincidence. The contract is “Copy tests should use isolated disposable fixtures rather than live homework folders.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Use tempfile.TemporaryDirectory and create every fixture inside it.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Tests belong in temporary directories” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Copy tests should use isolated disposable fixtures rather than live homework folders.” should remain invariant and what observation would expose experimenting inside Documents and hoping cleanup is correct.

Reasoned route. Begin with “Copy tests should use isolated disposable fixtures rather than live homework folders.” Apply this procedure: Use tempfile.TemporaryDirectory and create every fixture inside it. For the homework evidence folder, introduce one controlled variation that exposes experimenting inside Documents and hoping cleanup is correct. The test can be repeated without endangering personal data. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Tests belong in temporary directories” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Copy tests should use isolated disposable fixtures rather than live homework folders.” should remain invariant and what observation would expose experimenting inside Documents and hoping cleanup is correct.

Reasoned route. Begin with “Copy tests should use isolated disposable fixtures rather than live homework folders.” Apply this procedure: Use tempfile.TemporaryDirectory and create every fixture inside it. For the CCA media catalogue, introduce one controlled variation that exposes experimenting inside Documents and hoping cleanup is correct. The test can be repeated without endangering personal data. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Tests belong in temporary directories” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Copy tests should use isolated disposable fixtures rather than live homework folders.” should remain invariant and what observation would expose experimenting inside Documents and hoping cleanup is correct.

Reasoned route. Begin with “Copy tests should use isolated disposable fixtures rather than live homework folders.” Apply this procedure: Use tempfile.TemporaryDirectory and create every fixture inside it. For the science investigation archive, introduce one controlled variation that exposes experimenting inside Documents and hoping cleanup is correct. The test can be repeated without endangering personal data. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Tests belong in temporary directories” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Copy tests should use isolated disposable fixtures rather than live homework folders.” should remain invariant and what observation would expose experimenting inside Documents and hoping cleanup is correct.

Reasoned route. Begin with “Copy tests should use isolated disposable fixtures rather than live homework folders.” Apply this procedure: Use tempfile.TemporaryDirectory and create every fixture inside it. For the revision-note builder, introduce one controlled variation that exposes experimenting inside Documents and hoping cleanup is correct. The test can be repeated without endangering personal data. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals experimenting inside Documents and hoping cleanup is correct.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Use tempfile.TemporaryDirectory and create every fixture inside it.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Tests belong in temporary directories”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Copy tests should use isolated disposable fixtures rather than live homework folders.?”, and “Can you make a smaller example of experimenting inside Documents and hoping cleanup is correct?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Design a link-policy test inside one temporary root. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. All paths and cleanup remain bounded to the fixture. The final output alone earns only partial credit. A strong answer connects it to “Copy tests should use isolated disposable fixtures rather than live homework folders.”, shows the relevant intermediate evidence and states why experimenting inside Documents and hoping cleanup is correct would lead to a different conclusion.

Decision and transfer

Never learn destructive filesystem behaviour on irreplaceable work. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Tests belong in temporary directories” means the learner can predict the ordinary case, recognise experimenting inside Documents and hoping cleanup is correct, diagnose the earliest mistaken assumption, recover with “Use tempfile.TemporaryDirectory and create every fixture inside it.” and defend this decision: Never learn destructive filesystem behaviour on irreplaceable work. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

CHAPTER 20 OF 20 · Transfer with judgment

20. Choose the copy tool by the preservation contract

Back to contents

The right tool follows destination naming, recursion, link, metadata, version and collision requirements. That is the invariant to preserve when names, data or surrounding project details change.

One method name cannot decide all those policies. The useful question is not “Which line should I copy?” but “Which state, value or rendering decision does this operation control?” Answering that question prevents a correct-looking result from hiding a wrong mental model.

The most revealing near-miss is choosing the shortest line before defining what must survive. A learner should predict the result first, run the smallest safe case, label the observation and explain the earliest point where the prediction diverges. This turns an error into evidence rather than a verdict on ability.

Core worked example

copied=source.copy_into(target, follow_symlinks=False, preserve_metadata=True)

Explained result. The selected tool can then be justified against observable requirements. The explanation should identify the input, the governing rule, the observable outcome and one boundary that would change the conclusion. If any of those four parts is missing, reduce the example and trace it again.

Read the trace, not just the last line

Trace each argument back to one stated requirement. Write the trace as a sequence of labelled states. For Python pathlib.Path.copy_into, the decisive evidence may be an iterator close, a cached classification, a glyph-spacing decision or a repository object path; printing only the final Boolean or filename can hide the mechanism that produced it.

For “Choose the copy tool by the preservation contract”, separate contract from coincidence. The contract is “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Write a six-row decision table before implementation.” to decide whether another observation challenges the model or merely reflects the environment.

Four purposeful transfer cases

Case 1: homework evidence folder. Model “Choose the copy tool by the preservation contract” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” should remain invariant and what observation would expose choosing the shortest line before defining what must survive.

Reasoned route. Begin with “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” Apply this procedure: Write a six-row decision table before implementation. For the homework evidence folder, introduce one controlled variation that exposes choosing the shortest line before defining what must survive. The selected tool can then be justified against observable requirements. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 2: CCA media catalogue. Contrast “Choose the copy tool by the preservation contract” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” should remain invariant and what observation would expose choosing the shortest line before defining what must survive.

Reasoned route. Begin with “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” Apply this procedure: Write a six-row decision table before implementation. For the CCA media catalogue, introduce one controlled variation that exposes choosing the shortest line before defining what must survive. The selected tool can then be justified against observable requirements. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 3: science investigation archive. Stress-test “Choose the copy tool by the preservation contract” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” should remain invariant and what observation would expose choosing the shortest line before defining what must survive.

Reasoned route. Begin with “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” Apply this procedure: Write a six-row decision table before implementation. For the science investigation archive, introduce one controlled variation that exposes choosing the shortest line before defining what must survive. The selected tool can then be justified against observable requirements. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Case 4: revision-note builder. Explain “Choose the copy tool by the preservation contract” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” should remain invariant and what observation would expose choosing the shortest line before defining what must survive.

Reasoned route. Begin with “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.” Apply this procedure: Write a six-row decision table before implementation. For the revision-note builder, introduce one controlled variation that exposes choosing the shortest line before defining what must survive. The selected tool can then be justified against observable requirements. A complete answer explains why the near-miss fails, names the evidence that distinguishes it from the corrected case and transfers the rule without relying on the original variable names.

Diagnostic route

  • Model check: draw or list the exact values, objects, paths, characters or repository states before the operation.
  • Boundary check: construct the smallest safe input that reveals choosing the shortest line before defining what must survive.
  • Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
  • Repair check: Write a six-row decision table before implementation.
  • Transfer check: repeat the rule in a second context and name what remains unchanged.

A parent does not need to memorise Python pathlib.Path.copy_into to support “Choose the copy tool by the preservation contract”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests The right tool follows destination naming, recursion, link, metadata, version and collision requirements.?”, and “Can you make a smaller example of choosing the shortest line before defining what must survive?” These questions keep ownership with the learner while making the reasoning visible.

Practice with an explained answer

Task. Choose a route for an archival tree with meaningful symlinks. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.

Answer route. Preserve links and requested metadata only after confirming destination topology and platform support. The final output alone earns only partial credit. A strong answer connects it to “The right tool follows destination naming, recursion, link, metadata, version and collision requirements.”, shows the relevant intermediate evidence and states why choosing the shortest line before defining what must survive would lead to a different conclusion.

Decision and transfer

Prefer the smallest API whose documented contract matches the whole job. Prefer the choice whose semantics and failure modes are easiest to explain for the actual job. Shorter syntax is useful only when it preserves that clarity.

Mastery of “Choose the copy tool by the preservation contract” means the learner can predict the ordinary case, recognise choosing the shortest line before defining what must survive, diagnose the earliest mistaken assumption, recover with “Write a six-row decision table before implementation.” and defend this decision: Prefer the smallest API whose documented contract matches the whole job. Once that causal chain is stable, continue to the next chapter rather than adding repetitions of the same surface exercise.

Previous section · Contents · Next section

Parent guide: choose the next useful step

For Python pathlib.Path.copy_into, start with evidence rather than a label such as careless. Ask for one prediction and one trace. If the first transition is wrong, rebuild the model. If the model is sound but reference use is weak, practise finding the governing contract. If routine cases work but boundaries fail, vary one condition. If explanations transfer, move to a small project.

Punggol family routines are often busy, so use one complete Python pathlib.Path.copy_into prediction–observation–explanation cycle while attention is good. Ten to twenty focused minutes can be enough. Keep a four-line record: concept, prediction, observed difference and next test. Stop when fatigue replaces reasoning.

Use disposable fixtures, temporary directories and test repositories. Backups remain necessary. The activities in this guide are proposed home-learning exercises, not advertised lesson times, branch facilities, school affiliations or outcome guarantees.

Capstone practice with explained routes

1. Predict the returned path

Copy a named file into an existing temporary directory and draw the result before running. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: Path.copy_into(target_dir) places the source beneath target_dir rather than treating target_dir as the complete destination name. Apply: Draw source, target directory and target_dir/source.name before copying. Verify: The returned Path should name archive/notes.txt for a source named notes.txt. Then connect the result to the exact-destination contrast in Chapter 15. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

2. Copy a two-level tree

Build a tiny project tree and verify relative descendants beneath the returned Path. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: Path.copy and copy_into can copy a file or an entire directory tree. Apply: Build a tiny two-level fixture and inspect the returned tree. Verify: A directory source produces a same-named directory beneath target_dir with its descendants. Then connect the result to the manifest verification in Chapter 18. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

3. Compare link policies

Copy one disposable symlink with following enabled and disabled. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: With follow_symlinks=True, a source symlink is followed and its target is copied. Apply: Draw the link and target, then label which object supplies the copied data. Verify: The default route copies the target content rather than preserving link identity. Then connect the result to the topology warning in Chapter 8. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

4. Separate data from metadata

Verify bytes first, then inspect only supported metadata. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: With preserve_metadata=False, only directory structures and file data are guaranteed to be copied. Apply: Compare data integrity separately from metadata fields. Verify: The bytes and tree are the guaranteed core; other metadata may differ. Then connect the result to the platform limit in Chapter 11. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

5. Diagnose three failures

Create missing-target, wrong-kind and permission-oriented cases safely. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: copy_into can raise OSError subclasses for missing targets, permissions, collisions or unsupported operations. Apply: Catch OSError at the application boundary and retain type, source, target and message. Verify: The report distinguishes preparation, permission and collision problems. Then connect the result to the shared-state boundary in Chapter 14. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

6. Plan a Python 3.12 fallback

Write a compatibility decision without pretending APIs are identical. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: Older Python versions use shutil.copy, copy2 or copytree for related jobs. Apply: Define the minimum Python version or test a deliberate shutil fallback. Verify: Compatibility becomes explicit rather than failing at attribute access. Then connect the result to the version requirement in the introduction. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

7. Use a temporary fixture

Combine return-path, link and collision tests inside one temporary root. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: Copy tests should use isolated disposable fixtures rather than live homework folders. Apply: Use tempfile.TemporaryDirectory and create every fixture inside it. Verify: The test can be repeated without endangering personal data. Then connect the result to the risk-based verification in Chapter 18. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

8. Defend the tool choice

Compare copy_into, copy and shutil for three reader jobs. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.

Explained route. Start with: The right tool follows destination naming, recursion, link, metadata, version and collision requirements. Apply: Write a six-row decision table before implementation. Verify: The selected tool can then be justified against observable requirements. Then connect the result to the destination model in Chapter 1. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.

Frequently asked questions

How long should a practice session be?

Use one complete Python pathlib.Path.copy_into prediction–observation–explanation cycle while attention remains good. Ten to twenty focused minutes can be enough.

Should every option or method be memorised?

No. For Python pathlib.Path.copy_into, memorise governing distinctions and practise retrieving the primary reference. Understanding means predicting and explaining, not reciting a parameter list.

What if the result is correct but the explanation is weak?

Treat it as partial success. Ask for a trace and change one boundary. A reliable model survives controlled variation.

Is the shortest solution the best?

Not automatically. Prefer the solution whose semantics, failure modes and maintenance cost are easiest to justify for the actual project.

When should the official reference be used?

Use it whenever Python pathlib.Path.copy_into syntax, supported values, version behaviour or implementation boundaries matter. The primary source settles the current contract.

How can a parent help without technical expertise?

Ask what was predicted, where the first difference appeared, what evidence matters and which smaller example could isolate it.

How do we test transfer?

Change the context, vocabulary and one boundary. Require the learner to identify the invariant before using a tool.

What should be saved after practice?

Keep the corrected rule, one trace, one boundary case and the next question. Avoid storing pages of unexplained output.

Can these exercises replace backups?

No. Use disposable examples and proper backups. Learning should not endanger schoolwork, repositories or personal data.

What counts as mastery?

The learner can predict, verify, diagnose, recover and justify a choice across more than one context, while knowing when to consult the current reference.

Primary and supporting references

Return to contents

Continue from here: Start Here · Tuition · Education · Pathways · Parenting 101 · All Site Routes

eduKate Punggol

Contact

83 Punggol Central, Singapore 828761

edu|Kate Bukit Timah

8 Fourth Avenue, Singapore 268674

By Appointment +65 8823 1234
admin@edukatesg.com

Email Us

When a child finally understands, school becomes less frightening and the future opens wider. Email us for the latest schedules and fees.

← 返回

感谢您的回复。 ✨