Skip to content

Commit

Permalink
fix: dedent code samples
Browse files Browse the repository at this point in the history
Closes #146
  • Loading branch information
gvwilson committed Jul 7, 2023
1 parent ead701d commit 93ce653
Show file tree
Hide file tree
Showing 35 changed files with 1,465 additions and 1,464 deletions.
2 changes: 1 addition & 1 deletion docs/archive/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ <h2 id="archive-refactor">Section 10.4: Refactoring</h2>
Once we&rsquo;ve done this,
we can create the specific archiver we want with a single line:</p>
<div class="code-sample lang-py" title="backup_oop.py">
<div class="highlight"><pre><span></span><code> <span class="n">archiver</span> <span class="o">=</span> <span class="n">ArchiveLocal</span><span class="p">(</span><span class="n">source_dir</span><span class="p">,</span> <span class="n">backup_dir</span><span class="p">)</span>
<div class="highlight"><pre><span></span><code><span class="n">archiver</span> <span class="o">=</span> <span class="n">ArchiveLocal</span><span class="p">(</span><span class="n">source_dir</span><span class="p">,</span> <span class="n">backup_dir</span><span class="p">)</span>
</code></pre></div>
</div>
<p>Why go to this trouble?
Expand Down
2 changes: 1 addition & 1 deletion docs/archive/slides/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h1>A File Archiver</h1>
- Can then create the specific archiver we want

```py
archiver = ArchiveLocal(source_dir, backup_dir)
archiver = ArchiveLocal(source_dir, backup_dir)
```


Expand Down
32 changes: 16 additions & 16 deletions docs/bonus/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,14 @@ <h2 id="bonus-inheritance">Section B.3: Tracing Inheritance</h2>
record its parents,
and create an empty set to hold its methods:</p>
<div class="code-sample lang-py" title="inheritance.py">
<div class="highlight"><pre><span></span><code> <span class="k">def</span> <span class="nf">visit_ClassDef</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
<span class="n">class_name</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">name</span>
<span class="k">assert</span> <span class="n">class_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">class_name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">p</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">bases</span><span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generic_visit</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">visit_ClassDef</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
<span class="n">class_name</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">name</span>
<span class="k">assert</span> <span class="n">class_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">class_name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">p</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">bases</span><span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generic_visit</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
</code></pre></div>
</div>
<p>When we encounter a function definition,
Expand All @@ -668,14 +668,14 @@ <h2 id="bonus-inheritance">Section B.3: Tracing Inheritance</h2>
on the other hand,
we add its name to our records:</p>
<div class="code-sample lang-py" title="inheritance.py">
<div class="highlight"><pre><span></span><code> <span class="k">def</span> <span class="nf">visit_FunctionDef</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">:</span>
<span class="k">return</span>
<span class="n">class_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">assert</span> <span class="n">class_name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span>
<span class="n">method_name</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">name</span>
<span class="k">assert</span> <span class="n">method_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">method_name</span><span class="p">)</span>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">visit_FunctionDef</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">:</span>
<span class="k">return</span>
<span class="n">class_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stack</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">assert</span> <span class="n">class_name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span>
<span class="n">method_name</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">name</span>
<span class="k">assert</span> <span class="n">method_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">methods</span><span class="p">[</span><span class="n">class_name</span><span class="p">]</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">method_name</span><span class="p">)</span>
</code></pre></div>
</div>
<p>Once we&rsquo;re done searching the AST we print out a table
Expand Down
Loading

0 comments on commit 93ce653

Please sign in to comment.