When a learner sees a Path and asks “Is this a file or folder?”, the tempting answer is to call whichever method looks familiar. The deeper job is to decide whether cached type information is acceptable or whether the program needs a fresh filesystem query.
Python pathlib.Path.info is a PathInfo helper added in Python 3.14. Its methods can cache results, and Path objects produced by iterdir may arrive with file-type information learned while scanning the parent directory. Mastery means understanding that cache, stating symlink-following policy and choosing a fresh Path method when current information matters.
This guide teaches that decision through worked code, state traces, failure diagnosis, explained practice and transfer cases. It treats a changing filesystem honestly: a convenient classification is evidence from a moment, not an eternal snapshot.
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. Learn what the helper represents and what merely accessing it does.
Read the contract
Chapters 5–8. Use each query with explicit symlink semantics.
Test the boundary
Chapters 9–12. Test cache, broken-link and unavailable-path boundaries.
Diagnose and repair
Chapters 13–16. Separate stale information from a wrong path or permission issue.
Transfer with judgment
Chapters 17–20. Choose among info, direct Path queries and stat with judgment.
Open the full chapter index · Jump to capstone practice · Use the How Studying Works hub · Read the primary technical source
Complete chapter index
Chapters 1–4 · Build the model
Chapters 5–8 · Read the contract
Chapters 9–12 · Test the boundary
Chapters 13–16 · Diagnose and repair
CHAPTER 1 OF 20 · Build the model
1. Path.info returns a helper rather than a Boolean
Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink(). That is the invariant to preserve when names, data or surrounding project details change.
This distinction prevents learners from treating the helper itself as proof that a path exists. 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 testing if p.info is truthy and concluding that the target exists. 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
p = Path("missing.txt")
print(type(p.info).__name__)
print(p.info.exists())Explained result. The helper object can exist even when its query reports that the path does not. 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 Path construction, helper access and query result as three separate events. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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.info returns a helper rather than a Boolean”, separate contract from coincidence. The contract is “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Print the helper type, then call one named query and label the result.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Path.info returns a helper rather than a Boolean” 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.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” should remain invariant and what observation would expose testing if p.info is truthy and concluding that the target exists.
Reasoned route. Begin with “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” Apply this procedure: Print the helper type, then call one named query and label the result. For the homework evidence folder, introduce one controlled variation that exposes testing if p.info is truthy and concluding that the target exists. The helper object can exist even when its query reports that the path does not. 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.info returns a helper rather than a Boolean” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” should remain invariant and what observation would expose testing if p.info is truthy and concluding that the target exists.
Reasoned route. Begin with “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” Apply this procedure: Print the helper type, then call one named query and label the result. For the CCA media catalogue, introduce one controlled variation that exposes testing if p.info is truthy and concluding that the target exists. The helper object can exist even when its query reports that the path does not. 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.info returns a helper rather than a Boolean” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” should remain invariant and what observation would expose testing if p.info is truthy and concluding that the target exists.
Reasoned route. Begin with “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” Apply this procedure: Print the helper type, then call one named query and label the result. For the science investigation archive, introduce one controlled variation that exposes testing if p.info is truthy and concluding that the target exists. The helper object can exist even when its query reports that the path does not. 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.info returns a helper rather than a Boolean” 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.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” should remain invariant and what observation would expose testing if p.info is truthy and concluding that the target exists.
Reasoned route. Begin with “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().” Apply this procedure: Print the helper type, then call one named query and label the result. For the revision-note builder, introduce one controlled variation that exposes testing if p.info is truthy and concluding that the target exists. The helper object can exist even when its query reports that the path does not. 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 testing if p.info is truthy and concluding that the target exists.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Print the helper type, then call one named query and label the result.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Path.info returns a helper rather than a Boolean”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().?”, and “Can you make a smaller example of testing if p.info is truthy and concluding that the target exists?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. For an absent note file, predict p.info and p.info.exists(), then explain why the two expressions answer different questions. 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 property supplies the query interface; exists() supplies the existence result. The final output alone earns only partial credit. A strong answer connects it to “Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink().”, shows the relevant intermediate evidence and states why testing if p.info is truthy and concluding that the target exists would lead to a different conclusion.
Decision and transfer
Use the helper when several related type questions belong to one classification decision. 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.info returns a helper rather than a Boolean” means the learner can predict the ordinary case, recognise testing if p.info is truthy and concluding that the target exists, diagnose the earliest mistaken assumption, recover with “Print the helper type, then call one named query and label the result.” and defend this decision: Use the helper when several related type questions belong to one classification decision. 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. Accessing Path.info performs no filesystem query
Merely reading Path.info does not query the filesystem. That is the invariant to preserve when names, data or surrounding project details change.
The first meaningful operation is a PathInfo method, unless iterdir already supplied scan information. 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 timing property access and claiming it measured disk lookup. 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
p = Path("report.csv")
helper = p.info
print(helper)Explained result. Property access alone provides no evidence that the target was touched. 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
Mark the trace before and after helper access; no type verdict exists yet. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “Accessing Path.info performs no filesystem query”, separate contract from coincidence. The contract is “Merely reading Path.info does not query the filesystem.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Separate helper access from the first exists() or is_file() call in the trace.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Accessing Path.info performs no filesystem query” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “Merely reading Path.info does not query the filesystem.” should remain invariant and what observation would expose timing property access and claiming it measured disk lookup.
Reasoned route. Begin with “Merely reading Path.info does not query the filesystem.” Apply this procedure: Separate helper access from the first exists() or is_file() call in the trace. For the homework evidence folder, introduce one controlled variation that exposes timing property access and claiming it measured disk lookup. Property access alone provides no evidence that the target was touched. 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 “Accessing Path.info performs no filesystem query” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Merely reading Path.info does not query the filesystem.” should remain invariant and what observation would expose timing property access and claiming it measured disk lookup.
Reasoned route. Begin with “Merely reading Path.info does not query the filesystem.” Apply this procedure: Separate helper access from the first exists() or is_file() call in the trace. For the CCA media catalogue, introduce one controlled variation that exposes timing property access and claiming it measured disk lookup. Property access alone provides no evidence that the target was touched. 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 “Accessing Path.info performs no filesystem query” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Merely reading Path.info does not query the filesystem.” should remain invariant and what observation would expose timing property access and claiming it measured disk lookup.
Reasoned route. Begin with “Merely reading Path.info does not query the filesystem.” Apply this procedure: Separate helper access from the first exists() or is_file() call in the trace. For the science investigation archive, introduce one controlled variation that exposes timing property access and claiming it measured disk lookup. Property access alone provides no evidence that the target was touched. 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 “Accessing Path.info performs no filesystem query” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “Merely reading Path.info does not query the filesystem.” should remain invariant and what observation would expose timing property access and claiming it measured disk lookup.
Reasoned route. Begin with “Merely reading Path.info does not query the filesystem.” Apply this procedure: Separate helper access from the first exists() or is_file() call in the trace. For the revision-note builder, introduce one controlled variation that exposes timing property access and claiming it measured disk lookup. Property access alone provides no evidence that the target was touched. 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 timing property access and claiming it measured disk lookup.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Separate helper access from the first exists() or is_file() call in the trace.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Accessing Path.info performs no filesystem query”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Merely reading Path.info does not query the filesystem.?”, and “Can you make a smaller example of timing property access and claiming it measured disk lookup?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Explain which line can first require file-type information and why the assignment alone cannot confirm it. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. A query method, not the property read, asks for a classification. The final output alone earns only partial credit. A strong answer connects it to “Merely reading Path.info does not query the filesystem.”, shows the relevant intermediate evidence and states why timing property access and claiming it measured disk lookup would lead to a different conclusion.
Decision and transfer
This matters when profiling: measure the actual classification path, not a harmless accessor. 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 “Accessing Path.info performs no filesystem query” means the learner can predict the ordinary case, recognise timing property access and claiming it measured disk lookup, diagnose the earliest mistaken assumption, recover with “Separate helper access from the first exists() or is_file() call in the trace.” and defend this decision: This matters when profiling: measure the actual classification path, not a harmless accessor. 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
A PathInfo implementation may cache the result of each type query. That is the invariant to preserve when names, data or surrounding project details change.
Repeated convenience calls can describe earlier state after the filesystem changes. 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 a second is_file() call must repeat the operating-system check. 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
p = Path("draft.txt")
first = p.info.is_file()
second = p.info.is_file()
print(first, second)Explained result. A repeated method may reuse its first answer; the fresh object starts with an empty info cache. 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
Record object identity, query name and filesystem change separately. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “PathInfo methods may cache their results”, separate contract from coincidence. The contract is “A PathInfo implementation may cache the result of each type query.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Query once, change only a disposable target, query again, then compare with a fresh Path object.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “PathInfo methods may cache their results” 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 PathInfo implementation may cache the result of each type query.” should remain invariant and what observation would expose assuming a second is_file() call must repeat the operating-system check.
Reasoned route. Begin with “A PathInfo implementation may cache the result of each type query.” Apply this procedure: Query once, change only a disposable target, query again, then compare with a fresh Path object. For the homework evidence folder, introduce one controlled variation that exposes assuming a second is_file() call must repeat the operating-system check. A repeated method may reuse its first answer; the fresh object starts with an empty info cache. 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 “PathInfo methods may cache their results” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A PathInfo implementation may cache the result of each type query.” should remain invariant and what observation would expose assuming a second is_file() call must repeat the operating-system check.
Reasoned route. Begin with “A PathInfo implementation may cache the result of each type query.” Apply this procedure: Query once, change only a disposable target, query again, then compare with a fresh Path object. For the CCA media catalogue, introduce one controlled variation that exposes assuming a second is_file() call must repeat the operating-system check. A repeated method may reuse its first answer; the fresh object starts with an empty info cache. 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 “PathInfo methods may cache their results” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A PathInfo implementation may cache the result of each type query.” should remain invariant and what observation would expose assuming a second is_file() call must repeat the operating-system check.
Reasoned route. Begin with “A PathInfo implementation may cache the result of each type query.” Apply this procedure: Query once, change only a disposable target, query again, then compare with a fresh Path object. For the science investigation archive, introduce one controlled variation that exposes assuming a second is_file() call must repeat the operating-system check. A repeated method may reuse its first answer; the fresh object starts with an empty info cache. 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 “PathInfo methods may cache their results” 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 PathInfo implementation may cache the result of each type query.” should remain invariant and what observation would expose assuming a second is_file() call must repeat the operating-system check.
Reasoned route. Begin with “A PathInfo implementation may cache the result of each type query.” Apply this procedure: Query once, change only a disposable target, query again, then compare with a fresh Path object. For the revision-note builder, introduce one controlled variation that exposes assuming a second is_file() call must repeat the operating-system check. A repeated method may reuse its first answer; the fresh object starts with an empty info cache. 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 a second is_file() call must repeat the operating-system check.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Query once, change only a disposable target, query again, then compare with a fresh Path object.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “PathInfo methods may cache their results”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A PathInfo implementation may cache the result of each type query.?”, and “Can you make a smaller example of assuming a second is_file() call must repeat the operating-system check?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Design a safe experiment that can reveal caching without depending on a particular platform optimisation. 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 valid conclusion is that caching is permitted, not that every platform must show one exact syscall count. The final output alone earns only partial credit. A strong answer connects it to “A PathInfo implementation may cache the result of each type query.”, shows the relevant intermediate evidence and states why assuming a second is_file() call must repeat the operating-system check would lead to a different conclusion.
Decision and transfer
Do not use cached classification as a security guarantee or atomic filesystem snapshot. 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 “PathInfo methods may cache their results” means the learner can predict the ordinary case, recognise assuming a second is_file() call must repeat the operating-system check, diagnose the earliest mistaken assumption, recover with “Query once, change only a disposable target, query again, then compare with a fresh Path object.” and defend this decision: Do not use cached classification as a security guarantee or atomic filesystem snapshot. 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
A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory. That is the invariant to preserve when names, data or surrounding project details change.
This is where Path.info can reduce extra system calls in a classification loop. 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 reconstructing every child from its string before using info and discarding scan information. 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
for child in Path("workspace").iterdir():
print(child.name, child.info.is_dir())Explained result. The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. 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 parent scan, yielded child and subsequent type query in that order. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “iterdir can prefill file-type information”, separate contract from coincidence. The contract is “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Compare children used directly from iterdir with newly constructed Path(child) objects.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “iterdir can prefill file-type information” 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 Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” should remain invariant and what observation would expose reconstructing every child from its string before using info and discarding scan information.
Reasoned route. Begin with “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” Apply this procedure: Compare children used directly from iterdir with newly constructed Path(child) objects. For the homework evidence folder, introduce one controlled variation that exposes reconstructing every child from its string before using info and discarding scan information. The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. 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 “iterdir can prefill file-type information” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” should remain invariant and what observation would expose reconstructing every child from its string before using info and discarding scan information.
Reasoned route. Begin with “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” Apply this procedure: Compare children used directly from iterdir with newly constructed Path(child) objects. For the CCA media catalogue, introduce one controlled variation that exposes reconstructing every child from its string before using info and discarding scan information. The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. 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 “iterdir can prefill file-type information” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” should remain invariant and what observation would expose reconstructing every child from its string before using info and discarding scan information.
Reasoned route. Begin with “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” Apply this procedure: Compare children used directly from iterdir with newly constructed Path(child) objects. For the science investigation archive, introduce one controlled variation that exposes reconstructing every child from its string before using info and discarding scan information. The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. 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 “iterdir can prefill file-type information” 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 Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” should remain invariant and what observation would expose reconstructing every child from its string before using info and discarding scan information.
Reasoned route. Begin with “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.” Apply this procedure: Compare children used directly from iterdir with newly constructed Path(child) objects. For the revision-note builder, introduce one controlled variation that exposes reconstructing every child from its string before using info and discarding scan information. The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. 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 reconstructing every child from its string before using info and discarding scan information.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Compare children used directly from iterdir with newly constructed Path(child) objects.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “iterdir can prefill file-type information”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.?”, and “Can you make a smaller example of reconstructing every child from its string before using info and discarding scan information?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Filter directory entries into files and folders while preserving the yielded Path objects. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. Using the yielded objects keeps the opportunity for scan-derived information. The final output alone earns only partial credit. A strong answer connects it to “A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory.”, shows the relevant intermediate evidence and states why reconstructing every child from its string before using info and discarding scan information would lead to a different conclusion.
Decision and transfer
Prefer this pattern for broad directory classification where momentary type information is sufficient. 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 “iterdir can prefill file-type information” means the learner can predict the ordinary case, recognise reconstructing every child from its string before using info and discarding scan information, diagnose the earliest mistaken assumption, recover with “Compare children used directly from iterdir with newly constructed Path(child) objects.” and defend this decision: Prefer this pattern for broad directory classification where momentary type information is sufficient. 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
PathInfo.exists() answers whether the path exists as any kind of filesystem object. That is the invariant to preserve when names, data or surrounding project details change.
It is the broadest query and should not be mistaken for regular-file proof. 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 exists() before read_text() and assuming the target is readable text. 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
p = Path("input")
if p.info.exists():
print("present")Explained result. True existence does not promise regular-file type, permissions, stable identity or successful later opening. 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
Expand the trace from presence to kind to attempted operation. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “exists separates presence from kind”, separate contract from coincidence. The contract is “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “After exists(), ask the narrower kind and operation questions needed by the task.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “exists separates presence from kind” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” should remain invariant and what observation would expose using exists() before read_text() and assuming the target is readable text.
Reasoned route. Begin with “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” Apply this procedure: After exists(), ask the narrower kind and operation questions needed by the task. For the homework evidence folder, introduce one controlled variation that exposes using exists() before read_text() and assuming the target is readable text. True existence does not promise regular-file type, permissions, stable identity or successful later opening. 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 “exists separates presence from kind” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” should remain invariant and what observation would expose using exists() before read_text() and assuming the target is readable text.
Reasoned route. Begin with “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” Apply this procedure: After exists(), ask the narrower kind and operation questions needed by the task. For the CCA media catalogue, introduce one controlled variation that exposes using exists() before read_text() and assuming the target is readable text. True existence does not promise regular-file type, permissions, stable identity or successful later opening. 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 “exists separates presence from kind” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” should remain invariant and what observation would expose using exists() before read_text() and assuming the target is readable text.
Reasoned route. Begin with “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” Apply this procedure: After exists(), ask the narrower kind and operation questions needed by the task. For the science investigation archive, introduce one controlled variation that exposes using exists() before read_text() and assuming the target is readable text. True existence does not promise regular-file type, permissions, stable identity or successful later opening. 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 “exists separates presence from kind” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” should remain invariant and what observation would expose using exists() before read_text() and assuming the target is readable text.
Reasoned route. Begin with “PathInfo.exists() answers whether the path exists as any kind of filesystem object.” Apply this procedure: After exists(), ask the narrower kind and operation questions needed by the task. For the revision-note builder, introduce one controlled variation that exposes using exists() before read_text() and assuming the target is readable text. True existence does not promise regular-file type, permissions, stable identity or successful later opening. 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 exists() before read_text() and assuming the target is readable text.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: After exists(), ask the narrower kind and operation questions needed by the task.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “exists separates presence from kind”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests PathInfo.exists() answers whether the path exists as any kind of filesystem object.?”, and “Can you make a smaller example of using exists() before read_text() and assuming the target is readable text?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Classify a directory, file and missing path with exists(), then state what remains unknown. 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 existing object kinds can produce true; only the missing path must produce false. The final output alone earns only partial credit. A strong answer connects it to “PathInfo.exists() answers whether the path exists as any kind of filesystem object.”, shows the relevant intermediate evidence and states why using exists() before read_text() and assuming the target is readable text would lead to a different conclusion.
Decision and transfer
Use exists for presence-sensitive reporting, not as a substitute for handling the operation that follows. 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 “exists separates presence from kind” means the learner can predict the ordinary case, recognise using exists() before read_text() and assuming the target is readable text, diagnose the earliest mistaken assumption, recover with “After exists(), ask the narrower kind and operation questions needed by the task.” and defend this decision: Use exists for presence-sensitive reporting, not as a substitute for handling the operation that follows. 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
PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file. That is the invariant to preserve when names, data or surrounding project details change.
The follow_symlinks parameter determines whether the link target participates in classification. 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 is_file() and describing the directory entry itself as a regular 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
p.info.is_file()
p.info.is_file(follow_symlinks=False)Explained result. With following enabled the target can make the query true; with following disabled the symlink is not a regular 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
Draw two nodes—the link and target—before predicting either result. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “is_file includes symlink-following policy”, separate contract from coincidence. The contract is “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Compare follow_symlinks=True and False on a disposable link and label target versus link.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “is_file includes symlink-following policy” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” should remain invariant and what observation would expose calling is_file() and describing the directory entry itself as a regular file.
Reasoned route. Begin with “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” Apply this procedure: Compare follow_symlinks=True and False on a disposable link and label target versus link. For the homework evidence folder, introduce one controlled variation that exposes calling is_file() and describing the directory entry itself as a regular file. With following enabled the target can make the query true; with following disabled the symlink is not a regular 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 “is_file includes symlink-following policy” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” should remain invariant and what observation would expose calling is_file() and describing the directory entry itself as a regular file.
Reasoned route. Begin with “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” Apply this procedure: Compare follow_symlinks=True and False on a disposable link and label target versus link. For the CCA media catalogue, introduce one controlled variation that exposes calling is_file() and describing the directory entry itself as a regular file. With following enabled the target can make the query true; with following disabled the symlink is not a regular 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 “is_file includes symlink-following policy” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” should remain invariant and what observation would expose calling is_file() and describing the directory entry itself as a regular file.
Reasoned route. Begin with “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” Apply this procedure: Compare follow_symlinks=True and False on a disposable link and label target versus link. For the science investigation archive, introduce one controlled variation that exposes calling is_file() and describing the directory entry itself as a regular file. With following enabled the target can make the query true; with following disabled the symlink is not a regular 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 “is_file includes symlink-following policy” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” should remain invariant and what observation would expose calling is_file() and describing the directory entry itself as a regular file.
Reasoned route. Begin with “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.” Apply this procedure: Compare follow_symlinks=True and False on a disposable link and label target versus link. For the revision-note builder, introduce one controlled variation that exposes calling is_file() and describing the directory entry itself as a regular file. With following enabled the target can make the query true; with following disabled the symlink is not a regular 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 calling is_file() and describing the directory entry itself as a regular file.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Compare follow_symlinks=True and False on a disposable link and label target versus link.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “is_file includes symlink-following policy”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.?”, and “Can you make a smaller example of calling is_file() and describing the directory entry itself as a regular file?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. For a symlink to notes.txt, predict both calls and justify each noun in the answer. 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 first classifies through the link; the second classifies the link object itself. The final output alone earns only partial credit. A strong answer connects it to “PathInfo.is_file() is true for a regular file and, by default, for a symlink pointing to a file.”, shows the relevant intermediate evidence and states why calling is_file() and describing the directory entry itself as a regular file would lead to a different conclusion.
Decision and transfer
Choose the flag from the job: content processing often follows, inventory and safety checks often need link identity. 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 “is_file includes symlink-following policy” means the learner can predict the ordinary case, recognise calling is_file() and describing the directory entry itself as a regular file, diagnose the earliest mistaken assumption, recover with “Compare follow_symlinks=True and False on a disposable link and label target versus link.” and defend this decision: Choose the flag from the job: content processing often follows, inventory and safety checks often need link identity. 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
PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory. That is the invariant to preserve when names, data or surrounding project details change.
Directory traversal decisions can change sharply when links are followed. 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 a directory-targeting symlink as an ordinary directory without deciding recursion policy. 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
p.info.is_dir()
p.info.is_dir(follow_symlinks=False)Explained result. The target can satisfy the default query, while follow_symlinks=False keeps the link distinct. 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
Record entry kind, target kind and traversal choice as separate fields. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “is_dir applies the same target distinction”, separate contract from coincidence. The contract is “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Run both follow settings before any descent and keep the fixture cycle-free.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “is_dir applies the same target distinction” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” should remain invariant and what observation would expose treating a directory-targeting symlink as an ordinary directory without deciding recursion policy.
Reasoned route. Begin with “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” Apply this procedure: Run both follow settings before any descent and keep the fixture cycle-free. For the homework evidence folder, introduce one controlled variation that exposes treating a directory-targeting symlink as an ordinary directory without deciding recursion policy. The target can satisfy the default query, while follow_symlinks=False keeps the link distinct. 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 “is_dir applies the same target distinction” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” should remain invariant and what observation would expose treating a directory-targeting symlink as an ordinary directory without deciding recursion policy.
Reasoned route. Begin with “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” Apply this procedure: Run both follow settings before any descent and keep the fixture cycle-free. For the CCA media catalogue, introduce one controlled variation that exposes treating a directory-targeting symlink as an ordinary directory without deciding recursion policy. The target can satisfy the default query, while follow_symlinks=False keeps the link distinct. 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 “is_dir applies the same target distinction” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” should remain invariant and what observation would expose treating a directory-targeting symlink as an ordinary directory without deciding recursion policy.
Reasoned route. Begin with “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” Apply this procedure: Run both follow settings before any descent and keep the fixture cycle-free. For the science investigation archive, introduce one controlled variation that exposes treating a directory-targeting symlink as an ordinary directory without deciding recursion policy. The target can satisfy the default query, while follow_symlinks=False keeps the link distinct. 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 “is_dir applies the same target distinction” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” should remain invariant and what observation would expose treating a directory-targeting symlink as an ordinary directory without deciding recursion policy.
Reasoned route. Begin with “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.” Apply this procedure: Run both follow settings before any descent and keep the fixture cycle-free. For the revision-note builder, introduce one controlled variation that exposes treating a directory-targeting symlink as an ordinary directory without deciding recursion policy. The target can satisfy the default query, while follow_symlinks=False keeps the link distinct. 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 a directory-targeting symlink as an ordinary directory without deciding recursion policy.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Run both follow settings before any descent and keep the fixture cycle-free.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “is_dir applies the same target distinction”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.?”, and “Can you make a smaller example of treating a directory-targeting symlink as an ordinary directory without deciding recursion policy?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Classify a link to an archive folder and decide whether a recursive tool should descend. 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 classification answer and the traversal decision are related but not identical. The final output alone earns only partial credit. A strong answer connects it to “PathInfo.is_dir() is true for a directory and, by default, for a symlink pointing to a directory.”, shows the relevant intermediate evidence and states why treating a directory-targeting symlink as an ordinary directory without deciding recursion policy would lead to a different conclusion.
Decision and transfer
Use an explicit link policy before recursion; a cached directory verdict is not cycle detection. 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 “is_dir applies the same target distinction” means the learner can predict the ordinary case, recognise treating a directory-targeting symlink as an ordinary directory without deciding recursion policy, diagnose the earliest mistaken assumption, recover with “Run both follow settings before any descent and keep the fixture cycle-free.” and defend this decision: Use an explicit link policy before recursion; a cached directory verdict is not cycle detection. 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
PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing. That is the invariant to preserve when names, data or surrounding project details change.
Broken links are meaningful filesystem objects that default target-following queries can make look absent. 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 equating exists() false with “there is no directory entry here”. 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
print(link.info.is_symlink())
print(link.info.exists())Explained result. The link identity can remain true while target-following existence is false. 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 directory entry, link target and each query’s following rule. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “is_symlink recognises even a broken link”, separate contract from coincidence. The contract is “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Create a disposable link, remove its target and compare is_symlink() with exists().” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “is_symlink recognises even a broken link” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” should remain invariant and what observation would expose equating exists() false with “there is no directory entry here”.
Reasoned route. Begin with “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” Apply this procedure: Create a disposable link, remove its target and compare is_symlink() with exists(). For the homework evidence folder, introduce one controlled variation that exposes equating exists() false with “there is no directory entry here”. The link identity can remain true while target-following existence is false. 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 “is_symlink recognises even a broken link” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” should remain invariant and what observation would expose equating exists() false with “there is no directory entry here”.
Reasoned route. Begin with “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” Apply this procedure: Create a disposable link, remove its target and compare is_symlink() with exists(). For the CCA media catalogue, introduce one controlled variation that exposes equating exists() false with “there is no directory entry here”. The link identity can remain true while target-following existence is false. 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 “is_symlink recognises even a broken link” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” should remain invariant and what observation would expose equating exists() false with “there is no directory entry here”.
Reasoned route. Begin with “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” Apply this procedure: Create a disposable link, remove its target and compare is_symlink() with exists(). For the science investigation archive, introduce one controlled variation that exposes equating exists() false with “there is no directory entry here”. The link identity can remain true while target-following existence is false. 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 “is_symlink recognises even a broken link” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” should remain invariant and what observation would expose equating exists() false with “there is no directory entry here”.
Reasoned route. Begin with “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.” Apply this procedure: Create a disposable link, remove its target and compare is_symlink() with exists(). For the revision-note builder, introduce one controlled variation that exposes equating exists() false with “there is no directory entry here”. The link identity can remain true while target-following existence is false. 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 equating exists() false with “there is no directory entry here”.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Create a disposable link, remove its target and compare is_symlink() with exists().
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “is_symlink recognises even a broken link”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.?”, and “Can you make a smaller example of equating exists() false with “there is no directory entry here”?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Explain how a cleanup report should distinguish a broken link from a never-created 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 is_symlink for the entry and exists with an explicit policy for the target question. The final output alone earns only partial credit. A strong answer connects it to “PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing.”, shows the relevant intermediate evidence and states why equating exists() false with “there is no directory entry here” would lead to a different conclusion.
Decision and transfer
Keep both facts when broken-link repair or inventory 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 “is_symlink recognises even a broken link” means the learner can predict the ordinary case, recognise equating exists() false with “there is no directory entry here”, diagnose the earliest mistaken assumption, recover with “Create a disposable link, remove its target and compare is_symlink() with exists().” and defend this decision: Keep both facts when broken-link repair or inventory 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
PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist. That is the invariant to preserve when names, data or surrounding project details change.
This makes link-presence and target-presence separate testable questions. 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 unlabeled “exists” column in an inventory. 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
entry = p.info.exists(follow_symlinks=False)
target = p.info.exists()Explained result. A broken link may have entry_exists true and target_exists false. 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
Use a two-column truth table for intact link, broken link and missing name. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 changes exists semantics”, separate contract from coincidence. The contract is “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Store entry_exists and target_exists as different fields.” 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 changes exists semantics” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” should remain invariant and what observation would expose using one unlabeled “exists” column in an inventory.
Reasoned route. Begin with “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” Apply this procedure: Store entry_exists and target_exists as different fields. For the homework evidence folder, introduce one controlled variation that exposes using one unlabeled “exists” column in an inventory. A broken link may have entry_exists true and target_exists false. 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 changes exists semantics” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” should remain invariant and what observation would expose using one unlabeled “exists” column in an inventory.
Reasoned route. Begin with “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” Apply this procedure: Store entry_exists and target_exists as different fields. For the CCA media catalogue, introduce one controlled variation that exposes using one unlabeled “exists” column in an inventory. A broken link may have entry_exists true and target_exists false. 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 changes exists semantics” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” should remain invariant and what observation would expose using one unlabeled “exists” column in an inventory.
Reasoned route. Begin with “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” Apply this procedure: Store entry_exists and target_exists as different fields. For the science investigation archive, introduce one controlled variation that exposes using one unlabeled “exists” column in an inventory. A broken link may have entry_exists true and target_exists false. 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 changes exists semantics” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” should remain invariant and what observation would expose using one unlabeled “exists” column in an inventory.
Reasoned route. Begin with “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.” Apply this procedure: Store entry_exists and target_exists as different fields. For the revision-note builder, introduce one controlled variation that exposes using one unlabeled “exists” column in an inventory. A broken link may have entry_exists true and target_exists false. 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 unlabeled “exists” column in an inventory.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Store entry_exists and target_exists as different 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.info to support “follow_symlinks changes exists semantics”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.?”, and “Can you make a smaller example of using one unlabeled “exists” column in an inventory?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Complete the three-row truth table and explain the broken-link row. 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 row differs because one query follows and the other does not. The final output alone earns only partial credit. A strong answer connects it to “PathInfo.exists(follow_symlinks=False) can report a symlink entry without requiring its target to exist.”, shows the relevant intermediate evidence and states why using one unlabeled “exists” column in an inventory would lead to a different conclusion.
Decision and transfer
Name the question in code and output rather than relying on a bare exists variable. 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 changes exists semantics” means the learner can predict the ordinary case, recognise using one unlabeled “exists” column in an inventory, diagnose the earliest mistaken assumption, recover with “Store entry_exists and target_exists as different fields.” and defend this decision: Name the question in code and output rather than relying on a bare exists variable. 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
For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info. That is the invariant to preserve when names, data or surrounding project details change.
The direct methods express that currency matters more than cache reuse. 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 resetting a PathInfo cache by calling the same helper again. 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
fresh_file = p.is_file()
fresh_link = p.is_symlink()Explained result. The direct method is the documented route for current information; it still cannot freeze a changing filesystem. 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
Place the mutation, fresh query and later operation on a timeline. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “Fresh information needs direct Path methods”, separate contract from coincidence. The contract is “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Call a direct Path method or construct Path(p) when the decision requires a fresh query.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Fresh information needs direct Path methods” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” should remain invariant and what observation would expose resetting a PathInfo cache by calling the same helper again.
Reasoned route. Begin with “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” Apply this procedure: Call a direct Path method or construct Path(p) when the decision requires a fresh query. For the homework evidence folder, introduce one controlled variation that exposes resetting a PathInfo cache by calling the same helper again. The direct method is the documented route for current information; it still cannot freeze a changing filesystem. 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 “Fresh information needs direct Path methods” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” should remain invariant and what observation would expose resetting a PathInfo cache by calling the same helper again.
Reasoned route. Begin with “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” Apply this procedure: Call a direct Path method or construct Path(p) when the decision requires a fresh query. For the CCA media catalogue, introduce one controlled variation that exposes resetting a PathInfo cache by calling the same helper again. The direct method is the documented route for current information; it still cannot freeze a changing filesystem. 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 “Fresh information needs direct Path methods” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” should remain invariant and what observation would expose resetting a PathInfo cache by calling the same helper again.
Reasoned route. Begin with “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” Apply this procedure: Call a direct Path method or construct Path(p) when the decision requires a fresh query. For the science investigation archive, introduce one controlled variation that exposes resetting a PathInfo cache by calling the same helper again. The direct method is the documented route for current information; it still cannot freeze a changing filesystem. 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 “Fresh information needs direct Path methods” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” should remain invariant and what observation would expose resetting a PathInfo cache by calling the same helper again.
Reasoned route. Begin with “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.” Apply this procedure: Call a direct Path method or construct Path(p) when the decision requires a fresh query. For the revision-note builder, introduce one controlled variation that exposes resetting a PathInfo cache by calling the same helper again. The direct method is the documented route for current information; it still cannot freeze a changing filesystem. 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 resetting a PathInfo cache by calling the same helper again.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Call a direct Path method or construct Path(p) when the decision requires a fresh query.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Fresh information needs direct Path methods”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.?”, and “Can you make a smaller example of resetting a PathInfo cache by calling the same helper again?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. After replacing a disposable file with a directory, compare the cached helper decision with p.is_dir(). 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 direct method is the appropriate fresh classification check. The final output alone earns only partial credit. A strong answer connects it to “For up-to-date information, Python recommends Path.is_dir(), Path.is_file() and Path.is_symlink() rather than methods on Path.info.”, shows the relevant intermediate evidence and states why resetting a PathInfo cache by calling the same helper again would lead to a different conclusion.
Decision and transfer
Choose direct methods for state-sensitive decisions and still handle failure at the operation itself. 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 “Fresh information needs direct Path methods” means the learner can predict the ordinary case, recognise resetting a PathInfo cache by calling the same helper again, diagnose the earliest mistaken assumption, recover with “Call a direct Path method or construct Path(p) when the decision requires a fresh query.” and defend this decision: Choose direct methods for state-sensitive decisions and still handle failure at the operation itself. 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
There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache. That is the invariant to preserve when names, data or surrounding project details change.
Object renewal is the documented reset mechanism. 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 expecting del p.info or p.info.clear() to exist. 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
q = Path(p)
print(q.info.exists())Explained result. q names the same path text but owns a separate, initially empty information cache. 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 equal path values and distinct Python objects separately. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “A new Path object resets the info cache”, separate contract from coincidence. The contract is “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Construct q = Path(p), then make all later info queries through q.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “A new Path object resets the info cache” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” should remain invariant and what observation would expose expecting del p.info or p.info.clear() to exist.
Reasoned route. Begin with “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” Apply this procedure: Construct q = Path(p), then make all later info queries through q. For the homework evidence folder, introduce one controlled variation that exposes expecting del p.info or p.info.clear() to exist. q names the same path text but owns a separate, initially empty information cache. 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 “A new Path object resets the info cache” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” should remain invariant and what observation would expose expecting del p.info or p.info.clear() to exist.
Reasoned route. Begin with “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” Apply this procedure: Construct q = Path(p), then make all later info queries through q. For the CCA media catalogue, introduce one controlled variation that exposes expecting del p.info or p.info.clear() to exist. q names the same path text but owns a separate, initially empty information cache. 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 “A new Path object resets the info cache” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” should remain invariant and what observation would expose expecting del p.info or p.info.clear() to exist.
Reasoned route. Begin with “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” Apply this procedure: Construct q = Path(p), then make all later info queries through q. For the science investigation archive, introduce one controlled variation that exposes expecting del p.info or p.info.clear() to exist. q names the same path text but owns a separate, initially empty information cache. 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 “A new Path object resets the info cache” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” should remain invariant and what observation would expose expecting del p.info or p.info.clear() to exist.
Reasoned route. Begin with “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.” Apply this procedure: Construct q = Path(p), then make all later info queries through q. For the revision-note builder, introduce one controlled variation that exposes expecting del p.info or p.info.clear() to exist. q names the same path text but owns a separate, initially empty information cache. 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 expecting del p.info or p.info.clear() to exist.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Construct q = Path(p), then make all later info queries through q.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “A new Path object resets the info cache”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.?”, and “Can you make a smaller example of expecting del p.info or p.info.clear() to exist?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Explain why q == p can be true while their information-cache histories differ. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. Path equality concerns the path value; cache history belongs to the object’s helper state. The final output alone earns only partial credit. A strong answer connects it to “There is no PathInfo cache-reset method; Path(p) creates a new Path object with an empty info cache.”, shows the relevant intermediate evidence and states why expecting del p.info or p.info.clear() to exist would lead to a different conclusion.
Decision and transfer
Use a new object when a cache-aware workflow needs a clean classification phase. 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 “A new Path object resets the info cache” means the learner can predict the ordinary case, recognise expecting del p.info or p.info.clear() to exist, diagnose the earliest mistaken assumption, recover with “Construct q = Path(p), then make all later info queries through q.” and defend this decision: Use a new object when a cache-aware workflow needs a clean classification phase. 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
Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information. That is the invariant to preserve when names, data or surrounding project details change.
A Boolean kind query cannot replace the richer metadata contract. 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 four type predicates when one stat result is the real evidence. 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
st = p.stat()
print(st.st_size, st.st_mtime_ns)Explained result. The result supports several metadata decisions, while failure remains explicit. 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 query, returned stat object and derived decision. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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.stat provides explicit metadata”, separate contract from coincidence. The contract is “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Call stat once in a try block and derive the needed facts from the returned metadata.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Path.stat provides explicit metadata” 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.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” should remain invariant and what observation would expose calling four type predicates when one stat result is the real evidence.
Reasoned route. Begin with “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” Apply this procedure: Call stat once in a try block and derive the needed facts from the returned metadata. For the homework evidence folder, introduce one controlled variation that exposes calling four type predicates when one stat result is the real evidence. The result supports several metadata decisions, while failure remains explicit. 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.stat provides explicit metadata” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” should remain invariant and what observation would expose calling four type predicates when one stat result is the real evidence.
Reasoned route. Begin with “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” Apply this procedure: Call stat once in a try block and derive the needed facts from the returned metadata. For the CCA media catalogue, introduce one controlled variation that exposes calling four type predicates when one stat result is the real evidence. The result supports several metadata decisions, while failure remains explicit. 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.stat provides explicit metadata” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” should remain invariant and what observation would expose calling four type predicates when one stat result is the real evidence.
Reasoned route. Begin with “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” Apply this procedure: Call stat once in a try block and derive the needed facts from the returned metadata. For the science investigation archive, introduce one controlled variation that exposes calling four type predicates when one stat result is the real evidence. The result supports several metadata decisions, while failure remains explicit. 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.stat provides explicit metadata” 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.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” should remain invariant and what observation would expose calling four type predicates when one stat result is the real evidence.
Reasoned route. Begin with “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.” Apply this procedure: Call stat once in a try block and derive the needed facts from the returned metadata. For the revision-note builder, introduce one controlled variation that exposes calling four type predicates when one stat result is the real evidence. The result supports several metadata decisions, while failure remains explicit. 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 four type predicates when one stat result is the real evidence.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Call stat once in a try block and derive the needed facts from the returned metadata.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Path.stat provides explicit metadata”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.?”, and “Can you make a smaller example of calling four type predicates when one stat result is the real evidence?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Choose between info.is_file() and stat() for a report that needs byte size. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. stat is required because size is not part of the PathInfo protocol. The final output alone earns only partial credit. A strong answer connects it to “Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information.”, shows the relevant intermediate evidence and states why calling four type predicates when one stat result is the real evidence would lead to a different conclusion.
Decision and transfer
Use Path.info for type switching; use stat when metadata is the actual data 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 “Path.stat provides explicit metadata” means the learner can predict the ordinary case, recognise calling four type predicates when one stat result is the real evidence, diagnose the earliest mistaken assumption, recover with “Call stat once in a try block and derive the needed facts from the returned metadata.” and defend this decision: Use Path.info for type switching; use stat when metadata is the actual data 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
CHAPTER 13 OF 20 · Diagnose and repair
13. False can hide several inaccessible states
File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error. That is the invariant to preserve when names, data or surrounding project details change.
A false classification is not always a precise diagnosis. 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 printing “missing” for every false result. 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:
p.stat()
except OSError as exc:
print(type(exc).__name__, exc)Explained result. The diagnostic preserves the difference between absent, inaccessible and wrong-kind cases. 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 failing operation and the exception type rather than just the fallback label. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “False can hide several inaccessible states”, separate contract from coincidence. The contract is “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “When cause matters, call stat and handle specific OSError subclasses or record the exception.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “False can hide several inaccessible states” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” should remain invariant and what observation would expose printing “missing” for every false result.
Reasoned route. Begin with “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” Apply this procedure: When cause matters, call stat and handle specific OSError subclasses or record the exception. For the homework evidence folder, introduce one controlled variation that exposes printing “missing” for every false result. The diagnostic preserves the difference between absent, inaccessible and wrong-kind cases. 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 “False can hide several inaccessible states” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” should remain invariant and what observation would expose printing “missing” for every false result.
Reasoned route. Begin with “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” Apply this procedure: When cause matters, call stat and handle specific OSError subclasses or record the exception. For the CCA media catalogue, introduce one controlled variation that exposes printing “missing” for every false result. The diagnostic preserves the difference between absent, inaccessible and wrong-kind cases. 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 “False can hide several inaccessible states” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” should remain invariant and what observation would expose printing “missing” for every false result.
Reasoned route. Begin with “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” Apply this procedure: When cause matters, call stat and handle specific OSError subclasses or record the exception. For the science investigation archive, introduce one controlled variation that exposes printing “missing” for every false result. The diagnostic preserves the difference between absent, inaccessible and wrong-kind cases. 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 “False can hide several inaccessible states” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” should remain invariant and what observation would expose printing “missing” for every false result.
Reasoned route. Begin with “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.” Apply this procedure: When cause matters, call stat and handle specific OSError subclasses or record the exception. For the revision-note builder, introduce one controlled variation that exposes printing “missing” for every false result. The diagnostic preserves the difference between absent, inaccessible and wrong-kind cases. 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 printing “missing” for every false result.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: When cause matters, call stat and handle specific OSError subclasses or record the exception.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “False can hide several inaccessible states”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.?”, and “Can you make a smaller example of printing “missing” for every false result?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Design an error report that does not mislabel a permission problem as absence. 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 cause-revealing operation and retain the exception context. The final output alone earns only partial credit. A strong answer connects it to “File-type convenience methods can return false for invalid, inaccessible or missing paths in situations where stat would reveal an error.”, shows the relevant intermediate evidence and states why printing “missing” for every false result would lead to a different conclusion.
Decision and transfer
Prefer convenience false for tolerant filtering; prefer explicit errors for diagnosis and accountability. 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 “False can hide several inaccessible states” means the learner can predict the ordinary case, recognise printing “missing” for every false result, diagnose the earliest mistaken assumption, recover with “When cause matters, call stat and handle specific OSError subclasses or record the exception.” and defend this decision: Prefer convenience false for tolerant filtering; prefer explicit errors for diagnosis and accountability. 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. A cached result is not a filesystem snapshot
Path.info caching does not make several queries an atomic view of a changing filesystem. That is the invariant to preserve when names, data or surrounding project details change.
Another process can rename or replace an entry between classification 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 a successful is_file check as a guarantee that read_text will succeed on the same object. 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:
text = p.read_text(encoding="utf-8")
except OSError as exc:
print(exc)Explained result. The read may still fail or reach changed state; robust code handles that outcome. 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
Draw a timeline with check, external change and use. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “A cached result is not a filesystem snapshot”, separate contract from coincidence. The contract is “Path.info caching does not make several queries an atomic view of a changing filesystem.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Handle the file operation directly and treat classification as advisory when races matter.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “A cached result is not a filesystem snapshot” 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.info caching does not make several queries an atomic view of a changing filesystem.” should remain invariant and what observation would expose treating a successful is_file check as a guarantee that read_text will succeed on the same object.
Reasoned route. Begin with “Path.info caching does not make several queries an atomic view of a changing filesystem.” Apply this procedure: Handle the file operation directly and treat classification as advisory when races matter. For the homework evidence folder, introduce one controlled variation that exposes treating a successful is_file check as a guarantee that read_text will succeed on the same object. The read may still fail or reach changed state; robust code handles that outcome. 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 “A cached result is not a filesystem snapshot” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.info caching does not make several queries an atomic view of a changing filesystem.” should remain invariant and what observation would expose treating a successful is_file check as a guarantee that read_text will succeed on the same object.
Reasoned route. Begin with “Path.info caching does not make several queries an atomic view of a changing filesystem.” Apply this procedure: Handle the file operation directly and treat classification as advisory when races matter. For the CCA media catalogue, introduce one controlled variation that exposes treating a successful is_file check as a guarantee that read_text will succeed on the same object. The read may still fail or reach changed state; robust code handles that outcome. 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 “A cached result is not a filesystem snapshot” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.info caching does not make several queries an atomic view of a changing filesystem.” should remain invariant and what observation would expose treating a successful is_file check as a guarantee that read_text will succeed on the same object.
Reasoned route. Begin with “Path.info caching does not make several queries an atomic view of a changing filesystem.” Apply this procedure: Handle the file operation directly and treat classification as advisory when races matter. For the science investigation archive, introduce one controlled variation that exposes treating a successful is_file check as a guarantee that read_text will succeed on the same object. The read may still fail or reach changed state; robust code handles that outcome. 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 “A cached result is not a filesystem snapshot” 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.info caching does not make several queries an atomic view of a changing filesystem.” should remain invariant and what observation would expose treating a successful is_file check as a guarantee that read_text will succeed on the same object.
Reasoned route. Begin with “Path.info caching does not make several queries an atomic view of a changing filesystem.” Apply this procedure: Handle the file operation directly and treat classification as advisory when races matter. For the revision-note builder, introduce one controlled variation that exposes treating a successful is_file check as a guarantee that read_text will succeed on the same object. The read may still fail or reach changed state; robust code handles that outcome. 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 a successful is_file check as a guarantee that read_text will succeed on the same object.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Handle the file operation directly and treat classification as advisory when races matter.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “A cached result is not a filesystem snapshot”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.info caching does not make several queries an atomic view of a changing filesystem.?”, and “Can you make a smaller example of treating a successful is_file check as a guarantee that read_text will succeed on the same object?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Explain why check-then-open cannot eliminate a 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. The filesystem is shared mutable state; only the operation outcome settles that moment. The final output alone earns only partial credit. A strong answer connects it to “Path.info caching does not make several queries an atomic view of a changing filesystem.”, shows the relevant intermediate evidence and states why treating a successful is_file check as a guarantee that read_text will succeed on the same object would lead to a different conclusion.
Decision and transfer
Use classification for routing and user messages, not as an unbreakable precondition. 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 “A cached result is not a filesystem snapshot” means the learner can predict the ordinary case, recognise treating a successful is_file check as a guarantee that read_text will succeed on the same object, diagnose the earliest mistaken assumption, recover with “Handle the file operation directly and treat classification as advisory when races matter.” and defend this decision: Use classification for routing and user messages, not as an unbreakable precondition. 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. Directory filtering benefits from one classification chain
A classification chain should ask mutually useful questions in an order that reflects the task. That is the invariant to preserve when names, data or surrounding project details change.
An explicit chain avoids repeated ambiguous tests and makes “other kind” visible. 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 is_file and is_dir independently and forgetting symlinks or special files. 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 p.info.is_symlink(): kind="link"
elif p.info.is_dir(): kind="dir"
elif p.info.is_file(): kind="file"
elif p.info.exists(): kind="other"
else: kind="missing"Explained result. Each path reaches one intended reporting branch under the chosen policy. 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 true branch and explain why later branches are skipped. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 filtering benefits from one classification chain”, separate contract from coincidence. The contract is “A classification chain should ask mutually useful questions in an order that reflects the task.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Decide link policy, then test symlink, directory, file, exists and missing in a labelled order.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Directory filtering benefits from one classification chain” 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 classification chain should ask mutually useful questions in an order that reflects the task.” should remain invariant and what observation would expose checking is_file and is_dir independently and forgetting symlinks or special files.
Reasoned route. Begin with “A classification chain should ask mutually useful questions in an order that reflects the task.” Apply this procedure: Decide link policy, then test symlink, directory, file, exists and missing in a labelled order. For the homework evidence folder, introduce one controlled variation that exposes checking is_file and is_dir independently and forgetting symlinks or special files. Each path reaches one intended reporting branch under the chosen policy. 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 filtering benefits from one classification chain” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A classification chain should ask mutually useful questions in an order that reflects the task.” should remain invariant and what observation would expose checking is_file and is_dir independently and forgetting symlinks or special files.
Reasoned route. Begin with “A classification chain should ask mutually useful questions in an order that reflects the task.” Apply this procedure: Decide link policy, then test symlink, directory, file, exists and missing in a labelled order. For the CCA media catalogue, introduce one controlled variation that exposes checking is_file and is_dir independently and forgetting symlinks or special files. Each path reaches one intended reporting branch under the chosen policy. 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 filtering benefits from one classification chain” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A classification chain should ask mutually useful questions in an order that reflects the task.” should remain invariant and what observation would expose checking is_file and is_dir independently and forgetting symlinks or special files.
Reasoned route. Begin with “A classification chain should ask mutually useful questions in an order that reflects the task.” Apply this procedure: Decide link policy, then test symlink, directory, file, exists and missing in a labelled order. For the science investigation archive, introduce one controlled variation that exposes checking is_file and is_dir independently and forgetting symlinks or special files. Each path reaches one intended reporting branch under the chosen policy. 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 filtering benefits from one classification chain” 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 classification chain should ask mutually useful questions in an order that reflects the task.” should remain invariant and what observation would expose checking is_file and is_dir independently and forgetting symlinks or special files.
Reasoned route. Begin with “A classification chain should ask mutually useful questions in an order that reflects the task.” Apply this procedure: Decide link policy, then test symlink, directory, file, exists and missing in a labelled order. For the revision-note builder, introduce one controlled variation that exposes checking is_file and is_dir independently and forgetting symlinks or special files. Each path reaches one intended reporting branch under the chosen policy. 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 is_file and is_dir independently and forgetting symlinks or special files.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Decide link policy, then test symlink, directory, file, exists and missing in a labelled order.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Directory filtering benefits from one classification chain”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A classification chain should ask mutually useful questions in an order that reflects the task.?”, and “Can you make a smaller example of checking is_file and is_dir independently and forgetting symlinks or special files?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Build a small classifier for file, folder, link and absent 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. The result must reflect the declared following policy and preserve an “other” branch. The final output alone earns only partial credit. A strong answer connects it to “A classification chain should ask mutually useful questions in an order that reflects the task.”, shows the relevant intermediate evidence and states why checking is_file and is_dir independently and forgetting symlinks or special files would lead to a different conclusion.
Decision and transfer
Use a chain for reporting; use the actual operation for access. 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 filtering benefits from one classification chain” means the learner can predict the ordinary case, recognise checking is_file and is_dir independently and forgetting symlinks or special files, diagnose the earliest mistaken assumption, recover with “Decide link policy, then test symlink, directory, file, exists and missing in a labelled order.” and defend this decision: Use a chain for reporting; use the actual operation for access. 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. Performance claims need measurement at the right boundary
Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload. That is the invariant to preserve when names, data or surrounding project details change.
Responsible optimisation measures the real loop rather than repeating one cached call. 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 benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup. 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
for child in root.iterdir():
if child.info.is_file():
count += 1Explained result. The benchmark then reflects the intended workload and exposes whether the optimisation matters. 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
Count directory entries, operations and elapsed time while preserving identical outputs. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “Performance claims need measurement at the right boundary”, separate contract from coincidence. The contract is “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Measure complete scans, warm and cold conditions, representative entry mixes and correctness first.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Performance claims need measurement at the right boundary” 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.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” should remain invariant and what observation would expose benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup.
Reasoned route. Begin with “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” Apply this procedure: Measure complete scans, warm and cold conditions, representative entry mixes and correctness first. For the homework evidence folder, introduce one controlled variation that exposes benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup. The benchmark then reflects the intended workload and exposes whether the optimisation matters. 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 “Performance claims need measurement at the right boundary” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” should remain invariant and what observation would expose benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup.
Reasoned route. Begin with “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” Apply this procedure: Measure complete scans, warm and cold conditions, representative entry mixes and correctness first. For the CCA media catalogue, introduce one controlled variation that exposes benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup. The benchmark then reflects the intended workload and exposes whether the optimisation matters. 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 “Performance claims need measurement at the right boundary” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” should remain invariant and what observation would expose benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup.
Reasoned route. Begin with “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” Apply this procedure: Measure complete scans, warm and cold conditions, representative entry mixes and correctness first. For the science investigation archive, introduce one controlled variation that exposes benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup. The benchmark then reflects the intended workload and exposes whether the optimisation matters. 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 “Performance claims need measurement at the right boundary” 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.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” should remain invariant and what observation would expose benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup.
Reasoned route. Begin with “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.” Apply this procedure: Measure complete scans, warm and cold conditions, representative entry mixes and correctness first. For the revision-note builder, introduce one controlled variation that exposes benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup. The benchmark then reflects the intended workload and exposes whether the optimisation matters. 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 benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Measure complete scans, warm and cold conditions, representative entry mixes and correctness 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.info to support “Performance claims need measurement at the right boundary”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.?”, and “Can you make a smaller example of benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Propose an A/B scan comparing direct methods with info-based classification. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. Both variants must produce the same labelled inventory before timing is compared. The final output alone earns only partial credit. A strong answer connects it to “Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload.”, shows the relevant intermediate evidence and states why benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup would lead to a different conclusion.
Decision and transfer
Optimise only after the classification policy is correct and the workload shows a meaningful cost. 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 “Performance claims need measurement at the right boundary” means the learner can predict the ordinary case, recognise benchmarking p.info.is_file() one million times on one already-cached Path and claiming a directory-scan speedup, diagnose the earliest mistaken assumption, recover with “Measure complete scans, warm and cold conditions, representative entry mixes and correctness first.” and defend this decision: Optimise only after the classification policy is correct and the workload shows a meaningful cost. 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
A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache. That is the invariant to preserve when names, data or surrounding project details change.
Otherwise two tests can exercise different histories while appearing identical. 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 reusing one Path across mutation phases and blaming platform flakiness. 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
q = Path(p) # empty info cache
assert q.info.exists() is expectedExplained result. The test’s initial state and cache history become reproducible. 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
Record construction route beside each expected value. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 should control cache history”, separate contract from coincidence. The contract is “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Tests should control cache history” 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 cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” should remain invariant and what observation would expose reusing one Path across mutation phases and blaming platform flakiness.
Reasoned route. Begin with “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” Apply this procedure: Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject. For the homework evidence folder, introduce one controlled variation that exposes reusing one Path across mutation phases and blaming platform flakiness. The test’s initial state and cache history become reproducible. 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 should control cache history” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” should remain invariant and what observation would expose reusing one Path across mutation phases and blaming platform flakiness.
Reasoned route. Begin with “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” Apply this procedure: Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject. For the CCA media catalogue, introduce one controlled variation that exposes reusing one Path across mutation phases and blaming platform flakiness. The test’s initial state and cache history become reproducible. 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 should control cache history” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” should remain invariant and what observation would expose reusing one Path across mutation phases and blaming platform flakiness.
Reasoned route. Begin with “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” Apply this procedure: Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject. For the science investigation archive, introduce one controlled variation that exposes reusing one Path across mutation phases and blaming platform flakiness. The test’s initial state and cache history become reproducible. 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 should control cache history” 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 cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” should remain invariant and what observation would expose reusing one Path across mutation phases and blaming platform flakiness.
Reasoned route. Begin with “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.” Apply this procedure: Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject. For the revision-note builder, introduce one controlled variation that exposes reusing one Path across mutation phases and blaming platform flakiness. The test’s initial state and cache history become reproducible. 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 reusing one Path across mutation phases and blaming platform flakiness.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Tests should control cache history”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.?”, and “Can you make a smaller example of reusing one Path across mutation phases and blaming platform flakiness?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Write one test for scan-prefilled classification and another for a fresh Path. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. Separate tests reveal which behaviour is contractual and which is implementation opportunity. The final output alone earns only partial credit. A strong answer connects it to “A cache-sensitive test must state whether a Path came from iterdir, was constructed directly or was reconstructed to clear its cache.”, shows the relevant intermediate evidence and states why reusing one Path across mutation phases and blaming platform flakiness would lead to a different conclusion.
Decision and transfer
Keep cache-behaviour tests narrow; keep application tests focused on outcomes. 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 should control cache history” means the learner can predict the ordinary case, recognise reusing one Path across mutation phases and blaming platform flakiness, diagnose the earliest mistaken assumption, recover with “Create fresh fixtures and fresh Path objects for each assertion unless cache reuse is the subject.” and defend this decision: Keep cache-behaviour tests narrow; keep application tests focused on outcomes. 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. Python 3.14 is the compatibility boundary
Path.info and pathlib.types.PathInfo were added in Python 3.14. That is the invariant to preserve when names, data or surrounding project details change.
Code intended for older interpreters needs a version policy or fallback. 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 shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support. 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(Path("."), "info"):
kind = p.info.is_file()
else:
kind = p.is_file()Explained result. The supported range and fallback behaviour become explicit. 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 interpreter capability before the behavioural branch. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “Python 3.14 is the compatibility boundary”, separate contract from coincidence. The contract is “Path.info and pathlib.types.PathInfo were added in Python 3.14.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Declare requires-python >=3.14 or branch using feature detection and direct Path methods.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Python 3.14 is the compatibility boundary” 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.info and pathlib.types.PathInfo were added in Python 3.14.” should remain invariant and what observation would expose shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support.
Reasoned route. Begin with “Path.info and pathlib.types.PathInfo were added in Python 3.14.” Apply this procedure: Declare requires-python >=3.14 or branch using feature detection and direct Path methods. For the homework evidence folder, introduce one controlled variation that exposes shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support. The supported range and fallback behaviour become explicit. 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 “Python 3.14 is the compatibility boundary” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.info and pathlib.types.PathInfo were added in Python 3.14.” should remain invariant and what observation would expose shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support.
Reasoned route. Begin with “Path.info and pathlib.types.PathInfo were added in Python 3.14.” Apply this procedure: Declare requires-python >=3.14 or branch using feature detection and direct Path methods. For the CCA media catalogue, introduce one controlled variation that exposes shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support. The supported range and fallback behaviour become explicit. 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 “Python 3.14 is the compatibility boundary” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.info and pathlib.types.PathInfo were added in Python 3.14.” should remain invariant and what observation would expose shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support.
Reasoned route. Begin with “Path.info and pathlib.types.PathInfo were added in Python 3.14.” Apply this procedure: Declare requires-python >=3.14 or branch using feature detection and direct Path methods. For the science investigation archive, introduce one controlled variation that exposes shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support. The supported range and fallback behaviour become explicit. 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 “Python 3.14 is the compatibility boundary” 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.info and pathlib.types.PathInfo were added in Python 3.14.” should remain invariant and what observation would expose shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support.
Reasoned route. Begin with “Path.info and pathlib.types.PathInfo were added in Python 3.14.” Apply this procedure: Declare requires-python >=3.14 or branch using feature detection and direct Path methods. For the revision-note builder, introduce one controlled variation that exposes shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support. The supported range and fallback behaviour become explicit. 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 shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Declare requires-python >=3.14 or branch using feature detection and direct Path methods.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Python 3.14 is the compatibility boundary”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.info and pathlib.types.PathInfo were added in Python 3.14.?”, and “Can you make a smaller example of shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Design a compatibility note for a school lab that still runs 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 direct Path methods as the simple fallback and do not imply identical caching. The final output alone earns only partial credit. A strong answer connects it to “Path.info and pathlib.types.PathInfo were added in Python 3.14.”, shows the relevant intermediate evidence and states why shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support would lead to a different conclusion.
Decision and transfer
Prefer a clear minimum version when the new API is central; prefer a tested fallback when broad compatibility is required. 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 “Python 3.14 is the compatibility boundary” means the learner can predict the ordinary case, recognise shipping a library that imports PathInfo unconditionally while claiming Python 3.12 support, diagnose the earliest mistaken assumption, recover with “Declare requires-python >=3.14 or branch using feature detection and direct Path methods.” and defend this decision: Prefer a clear minimum version when the new API is central; prefer a tested fallback when broad compatibility is required. 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. Custom PathInfo implementations follow a protocol
pathlib.types.PathInfo is a typing protocol, and implementations may return cached results. That is the invariant to preserve when names, data or surrounding project details change.
Type compatibility describes available methods, not one storage strategy. 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 PathInfo must be CPython’s concrete internal helper. 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.types import PathInfo
def classify(info: PathInfo) -> str:
return "dir" if info.is_dir() else "other"Explained result. A conforming consumer relies on the protocol rather than private attributes. 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 only protocol-visible calls and results. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 “Custom PathInfo implementations follow a protocol”, separate contract from coincidence. The contract is “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” and comes from the primary specification or manual. Coincidence is what happened on one machine, font, filesystem or repository. Record both, then use “Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Custom PathInfo implementations follow a protocol” with subject folders, draft answers and a reviewed copy. Before touching a tool, state which part of the case corresponds to the input, why “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” should remain invariant and what observation would expose assuming every PathInfo must be CPython’s concrete internal helper.
Reasoned route. Begin with “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” Apply this procedure: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported. For the homework evidence folder, introduce one controlled variation that exposes assuming every PathInfo must be CPython’s concrete internal helper. A conforming consumer relies on the protocol rather than private attributes. 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 “Custom PathInfo implementations follow a protocol” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” should remain invariant and what observation would expose assuming every PathInfo must be CPython’s concrete internal helper.
Reasoned route. Begin with “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” Apply this procedure: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported. For the CCA media catalogue, introduce one controlled variation that exposes assuming every PathInfo must be CPython’s concrete internal helper. A conforming consumer relies on the protocol rather than private attributes. 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 “Custom PathInfo implementations follow a protocol” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” should remain invariant and what observation would expose assuming every PathInfo must be CPython’s concrete internal helper.
Reasoned route. Begin with “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” Apply this procedure: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported. For the science investigation archive, introduce one controlled variation that exposes assuming every PathInfo must be CPython’s concrete internal helper. A conforming consumer relies on the protocol rather than private attributes. 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 “Custom PathInfo implementations follow a protocol” with topic notes, worked examples and a generated index. Before touching a tool, state which part of the case corresponds to the input, why “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” should remain invariant and what observation would expose assuming every PathInfo must be CPython’s concrete internal helper.
Reasoned route. Begin with “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.” Apply this procedure: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported. For the revision-note builder, introduce one controlled variation that exposes assuming every PathInfo must be CPython’s concrete internal helper. A conforming consumer relies on the protocol rather than private attributes. 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 PathInfo must be CPython’s concrete internal helper.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Custom PathInfo implementations follow a protocol”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.?”, and “Can you make a smaller example of assuming every PathInfo must be CPython’s concrete internal helper?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. Explain why code that reads a private cache dictionary is less portable. 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 protocol promises methods, not private representation. The final output alone earns only partial credit. A strong answer connects it to “pathlib.types.PathInfo is a typing protocol, and implementations may return cached results.”, shows the relevant intermediate evidence and states why assuming every PathInfo must be CPython’s concrete internal helper would lead to a different conclusion.
Decision and transfer
Use the protocol for type checking and keep filesystem policy in the caller. 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 “Custom PathInfo implementations follow a protocol” means the learner can predict the ordinary case, recognise assuming every PathInfo must be CPython’s concrete internal helper, diagnose the earliest mistaken assumption, recover with “Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported.” and defend this decision: Use the protocol for type checking and keep filesystem policy in the caller. 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 info, direct methods or stat by reader job
Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis. That is the invariant to preserve when names, data or surrounding project details change.
The final skill is choosing the narrowest truthful tool. 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 favourite API for every presence, type, metadata and access problem. 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
question = "fresh kind"
answer = p.is_file()Explained result. The decision can be defended by required evidence rather than habit. 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
Map each reader job to the evidence it needs before writing code. Write the trace as a sequence of labelled states. For Python pathlib.Path.info, 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 info, direct methods or stat by reader job”, separate contract from coincidence. The contract is “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” 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 question first—cached classification, fresh kind, metadata or operation—then choose the API.” to decide whether another observation challenges the model or merely reflects the environment.
Four purposeful transfer cases
Case 1: homework evidence folder. Model “Choose info, direct methods or stat by reader job” 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.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” should remain invariant and what observation would expose using one favourite API for every presence, type, metadata and access problem.
Reasoned route. Begin with “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” Apply this procedure: Write the question first—cached classification, fresh kind, metadata or operation—then choose the API. For the homework evidence folder, introduce one controlled variation that exposes using one favourite API for every presence, type, metadata and access problem. The decision can be defended by required evidence rather than habit. 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 info, direct methods or stat by reader job” with event folders, selected images and caption notes. Before touching a tool, state which part of the case corresponds to the input, why “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” should remain invariant and what observation would expose using one favourite API for every presence, type, metadata and access problem.
Reasoned route. Begin with “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” Apply this procedure: Write the question first—cached classification, fresh kind, metadata or operation—then choose the API. For the CCA media catalogue, introduce one controlled variation that exposes using one favourite API for every presence, type, metadata and access problem. The decision can be defended by required evidence rather than habit. 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 info, direct methods or stat by reader job” with raw readings, cleaned tables and chart exports. Before touching a tool, state which part of the case corresponds to the input, why “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” should remain invariant and what observation would expose using one favourite API for every presence, type, metadata and access problem.
Reasoned route. Begin with “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” Apply this procedure: Write the question first—cached classification, fresh kind, metadata or operation—then choose the API. For the science investigation archive, introduce one controlled variation that exposes using one favourite API for every presence, type, metadata and access problem. The decision can be defended by required evidence rather than habit. 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 info, direct methods or stat by reader job” 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.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” should remain invariant and what observation would expose using one favourite API for every presence, type, metadata and access problem.
Reasoned route. Begin with “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.” Apply this procedure: Write the question first—cached classification, fresh kind, metadata or operation—then choose the API. For the revision-note builder, introduce one controlled variation that exposes using one favourite API for every presence, type, metadata and access problem. The decision can be defended by required evidence rather than habit. 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 favourite API for every presence, type, metadata and access problem.
- Evidence check: distinguish a displayed result from ownership, caching, consumption, font behaviour or object type.
- Repair check: Write the question first—cached classification, fresh kind, metadata or operation—then choose the API.
- Transfer check: repeat the rule in a second context and name what remains unchanged.
A parent does not need to memorise Python pathlib.Path.info to support “Choose info, direct methods or stat by reader job”. Useful prompts are: “What did you expect?”, “Which state changed first?”, “What evidence tests Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.?”, and “Can you make a smaller example of using one favourite API for every presence, type, metadata and access problem?” These questions keep ownership with the learner while making the reasoning visible.
Practice with an explained answer
Task. For a thumbnail index, backup verifier and file-size report, choose one API for each. Write the prediction before running anything. Include one ordinary case and one boundary case, then explain the difference in two causal sentences.
Answer route. Index may use info, verifier needs direct operation/fresh checks, and size report needs stat. The final output alone earns only partial credit. A strong answer connects it to “Path.info suits repeated type switching where cached or scan-derived information is acceptable; direct Path methods suit fresher classification; stat suits explicit metadata and error diagnosis.”, shows the relevant intermediate evidence and states why using one favourite API for every presence, type, metadata and access problem would lead to a different conclusion.
Decision and transfer
A good choice names acceptable staleness, symlink policy, error needs and the later operation. 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 info, direct methods or stat by reader job” means the learner can predict the ordinary case, recognise using one favourite API for every presence, type, metadata and access problem, diagnose the earliest mistaken assumption, recover with “Write the question first—cached classification, fresh kind, metadata or operation—then choose the API.” and defend this decision: A good choice names acceptable staleness, symlink policy, error needs and the later operation. 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.info, 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.info 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. Build a cache-aware homework archive classifier
Scan a temporary folder and label files, directories, links and missing references. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: A Path returned by Path.iterdir() may carry information gleaned from scanning its parent directory. Apply: Compare children used directly from iterdir with newly constructed Path(child) objects. Verify: The direct child may begin with scan-derived type information; the reconstructed path begins with an empty info cache. Then connect the result to the fresh-query decision in Chapter 10. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
2. Diagnose a broken-link report
Create an intact link and a broken link, then report entry and target presence separately. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: PathInfo.is_symlink() tests the entry itself and can be true even when the target is missing. Apply: Create a disposable link, remove its target and compare is_symlink() with exists(). Verify: The link identity can remain true while target-following existence is false. Then connect the result to the follow_symlinks truth table in Chapter 9. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
3. Plan a version-compatible lab exercise
Write a Python 3.12 fallback and a Python 3.14 path without inventing performance equivalence. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Path.info and pathlib.types.PathInfo were added in Python 3.14. Apply: Declare requires-python >=3.14 or branch using feature detection and direct Path methods. Verify: The supported range and fallback behaviour become explicit. Then connect the result to the tool-choice matrix in Chapter 20. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
4. Measure a directory inventory honestly
Compare two complete classification loops and verify identical output before timing. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Path.info can reduce system calls when switching on file type, especially after iterdir, but the benefit depends on platform and workload. Apply: Measure complete scans, warm and cold conditions, representative entry mixes and correctness first. Verify: The benchmark then reflects the intended workload and exposes whether the optimisation matters. Then connect the result to the cache-history controls in Chapter 17. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
5. Explain a check-then-use race
Draw a timeline in which an entry changes between classification and reading. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Path.info caching does not make several queries an atomic view of a changing filesystem. Apply: Handle the file operation directly and treat classification as advisory when races matter. Verify: The read may still fail or reach changed state; robust code handles that outcome. Then connect the result to the error-diagnostic route in Chapter 13. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
6. Design a parent-led debugging conversation
Use a missing file to separate the helper object from an existence result. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Path.info returns a PathInfo object; the Boolean answer comes from a method such as exists(), is_file(), is_dir() or is_symlink(). Apply: Print the helper type, then call one named query and label the result. Verify: The helper object can exist even when its query reports that the path does not. Then connect the result to the evidence questions used throughout the guide. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
7. Choose evidence for a metadata report
Produce a file-kind and size report with explicit error handling. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Path.stat() returns metadata and is the better tool when the program needs mode, size, timestamps or inode-related information. Apply: Call stat once in a try block and derive the needed facts from the returned metadata. Verify: The result supports several metadata decisions, while failure remains explicit. Then connect the result to the false-result ambiguity in Chapter 13. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement.
8. Transfer the model to a custom protocol
Describe a fake PathInfo used for testing without relying on private attributes. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: pathlib.types.PathInfo is a typing protocol, and implementations may return cached results. Apply: Program to exists, is_dir, is_file and is_symlink semantics, with explicit follow_symlinks where supported. Verify: A conforming consumer relies on the protocol rather than private attributes. Then connect the result to the final API-choice reasoning in Chapter 20. 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.info 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.info, 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.info 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.

