<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AmosQuety</title>
    <description>The latest articles on DEV Community by AmosQuety (@amosquety).</description>
    <link>https://dev.to/amosquety</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2326368%2Ff21e8440-c906-457b-adc5-082fc7484114.png</url>
      <title>DEV Community: AmosQuety</title>
      <link>https://dev.to/amosquety</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amosquety"/>
    <language>en</language>
    <item>
      <title>Why Your Python Docstrings Lie (And How to Fix It)</title>
      <dc:creator>AmosQuety</dc:creator>
      <pubDate>Wed, 10 Jun 2026 18:33:16 +0000</pubDate>
      <link>https://dev.to/amosquety/why-your-python-docstrings-lie-and-how-to-fix-it-1f31</link>
      <guid>https://dev.to/amosquety/why-your-python-docstrings-lie-and-how-to-fix-it-1f31</guid>
      <description>&lt;p&gt;Documentation drift is silent. Your code ships, your docstrings stay behind,&lt;br&gt;
and six months later a new developer reads this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_discount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Calculate discount.

    Args:
        price (float): Price of the object.
        rate (float): Rate of the object.

    Returns:
        float: Description of the return value.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Technically documented. Completely useless.&lt;/p&gt;




&lt;h2&gt;
  
  
  The real problem with AI-generated docstrings
&lt;/h2&gt;

&lt;p&gt;AI tools are great at filling the blank — they will generate &lt;em&gt;something&lt;/em&gt; for&lt;br&gt;
every function. But "something" is not the same as "accurate." The moment you&lt;br&gt;
rename a parameter, change a return type, or add a new exception, the docstring&lt;br&gt;
is already wrong. There is no enforcement. There is no drift detection.&lt;/p&gt;

&lt;p&gt;You end up with documentation that passes a quick glance but fails the developer&lt;br&gt;
who actually needs it.&lt;/p&gt;


&lt;h2&gt;
  
  
  What deterministic validation gives you
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://pypi.org/project/pycodecommenter/" rel="noopener noreferrer"&gt;PyCodeCommenter&lt;/a&gt; takes a different&lt;br&gt;
approach — rule-based, AST-driven, no external API calls. It does three things:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generate&lt;/strong&gt; — produces a starter docstring from the actual function signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pycodecommenter generate main.py &lt;span class="nt"&gt;-i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Validate&lt;/strong&gt; — checks six things against the real code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parameters in the docstring match parameters in the signature&lt;/li&gt;
&lt;li&gt;Type hints match documented types
&lt;/li&gt;
&lt;li&gt;Raised exceptions are documented&lt;/li&gt;
&lt;li&gt;Return values are documented&lt;/li&gt;
&lt;li&gt;Format follows Google-style guidelines&lt;/li&gt;
&lt;li&gt;No placeholders or TODOs left behind
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pycodecommenter validate main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Coverage&lt;/strong&gt; — gives you a project-wide documentation score:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pycodecommenter coverage ./src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Where it fits in a real workflow
&lt;/h2&gt;

&lt;p&gt;The most useful place is a pre-commit hook or CI step — not as a blocker on&lt;br&gt;
day one, but as a signal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .pre-commit-config.yaml&lt;/span&gt;
&lt;span class="na"&gt;repos&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;local&lt;/span&gt;
    &lt;span class="na"&gt;hooks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;validate-docstrings&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Validate Docstrings&lt;/span&gt;
        &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pycodecommenter validate .&lt;/span&gt;
        &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;system&lt;/span&gt;
        &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;python&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or in GitHub Actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Validate documentation&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pycodecommenter validate .&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now documentation drift gets caught at the PR stage, not six months later.&lt;/p&gt;




&lt;h2&gt;
  
  
  The new --dry-run flag (v2.1.0)
&lt;/h2&gt;

&lt;p&gt;The latest release adds a safety flag that shows you exactly what would change&lt;br&gt;
before touching any file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pycodecommenter generate main.py &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prints a unified diff to stdout. Exit code 1 if changes exist, 0 if clean —&lt;br&gt;
CI-friendly by design.&lt;/p&gt;

&lt;p&gt;Combined with &lt;code&gt;--backup&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pycodecommenter generate main.py &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;--backup&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Saves &lt;code&gt;main.py.bak&lt;/code&gt; before any in-place write. No more accidental overwrites.&lt;/p&gt;




&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;Drop a &lt;code&gt;.pycodecommenter.yaml&lt;/code&gt; in your project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;google&lt;/span&gt;
&lt;span class="na"&gt;validation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;strict&lt;/span&gt;
  &lt;span class="na"&gt;check_types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;check_exceptions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;coverage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
  &lt;span class="na"&gt;fail_below&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*/tests/*"&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*/migrations/*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pycodecommenter
pycodecommenter generate your_file.py &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project is open source under MIT.&lt;br&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/AmosQuety/PyCodeCommenter" rel="noopener noreferrer"&gt;AmosQuety/PyCodeCommenter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Built by &lt;a href="https://nabasa-amos.netlify.app" rel="noopener noreferrer"&gt;Nabasa Amos&lt;/a&gt; — a software engineer&lt;br&gt;
focused on developer tooling and open source.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>documentation</category>
      <category>tooling</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
