<?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: waldo</title>
    <description>The latest articles on DEV Community by waldo (@waldo870).</description>
    <link>https://dev.to/waldo870</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4209312%2Feecfdba0-f907-4654-8aac-ab48c8fdf6dd.png</url>
      <title>DEV Community: waldo</title>
      <link>https://dev.to/waldo870</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/waldo870"/>
    <language>en</language>
    <item>
      <title>Python’s isdigit() Can Accept More Than 0–9</title>
      <dc:creator>waldo</dc:creator>
      <pubDate>Mon, 26 Oct 2026 19:41:21 +0000</pubDate>
      <link>https://dev.to/waldo870/pythons-isdigit-can-accept-more-than-0-9-25oo</link>
      <guid>https://dev.to/waldo870/pythons-isdigit-can-accept-more-than-0-9-25oo</guid>
      <description>&lt;p&gt;A proposed fix can pass a normal example and still violate the requirement. Here is a small Python example you can inspect without installing anything beyond Python.&lt;/p&gt;

&lt;p&gt;The requirement is precise: accept a string only if it contains exactly eight characters, all ASCII digits from 0 to 9. Reject every other string. This is an access-code exercise, not a recommendation for designing passwords or authentication systems.&lt;/p&gt;

&lt;p&gt;In Challenge 03, a fictional AI assistant proposes this repair:&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;valid_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isdigit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For "12345678", the function returns True. Before accepting the repair, ask two separate questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Does it require exactly eight characters?&lt;/li&gt;
&lt;li&gt;Does it allow only the ten ASCII digits?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those questions point to two different defects.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. “At least eight” is not “exactly eight”
&lt;/h2&gt;

&lt;p&gt;Consider "123456789". Its characters are ordinary ASCII digits, but there are nine of them. The function still returns True because len(code) &amp;gt;= 8 accepts lengths greater than eight.&lt;/p&gt;

&lt;p&gt;This example isolates the length requirement. The characters are allowed; the length is wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. isdigit() is not an ASCII-only check
&lt;/h2&gt;

&lt;p&gt;Now consider "１２３４５６７８". These are eight full-width Unicode digits. They may look familiar, but they are not the ASCII characters in "12345678".&lt;/p&gt;

&lt;p&gt;Python’s isdigit() recognizes a broader digit category than this exercise permits. It returns True for that full-width string. The Python documentation describes the method’s Unicode behavior.&lt;/p&gt;

&lt;p&gt;Changing &amp;gt;= to == would repair the length check, but the full-width string would still pass. The second defect needs its own repair.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make each check match a requirement
&lt;/h2&gt;

&lt;p&gt;Here is the corrected answer from the challenge:&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;valid_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0123456789&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first check rejects the wrong length. The loop rejects characters outside the explicit allowed set. The function reaches True only after checking both requirements.&lt;/p&gt;

&lt;p&gt;The exercise assumes the input is a string. Converting arbitrary objects to strings would introduce a different requirement; it is not part of this repair.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the supplied examples
&lt;/h2&gt;

&lt;p&gt;These are the seven examples already included with the challenge:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input string&lt;/th&gt;
&lt;th&gt;Required result&lt;/th&gt;
&lt;th&gt;Proposed repair&lt;/th&gt;
&lt;th&gt;Corrected repair&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;"12345678"&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"1234567"&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"123456789"&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"12 45678"&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;""&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"１２３４５６７８"&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"00000000"&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The results above were reproduced for this example on CPython 3.12.14. The proposed repair fails two of the seven expectations; the corrected repair matches all seven. That is evidence about these cases, not a claim that every possible behavior of a larger program has been tested.&lt;/p&gt;

&lt;p&gt;Notice what the examples tell you. The nine-character string exposes the length defect. The full-width string exposes the character-set defect. The normal and all-zero strings help check that the repair preserves valid behavior. The empty and space-containing strings were already rejected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain why the fix works
&lt;/h2&gt;

&lt;p&gt;The useful habit here is to connect each test to a requirement. Before accepting an AI-generated fix, identify a case that could disprove it. After changing the code, explain the mismatch you removed and rerun the relevant examples.&lt;/p&gt;

&lt;p&gt;There is nothing inherently wrong with isdigit(). The problem was using it for a narrower rule than it actually implements.&lt;/p&gt;

&lt;p&gt;If you already know basic Python variables, conditions and loops, this is the kind of reasoning you can practise before taking on larger debugging problems.&lt;/p&gt;

&lt;p&gt;This example is from my US$9 practice pack, Vibe Coding Python Debugging Kit — Find Bugs, Test AI Fixes &amp;amp; Learn Python. The complete explanation above is free; you do not need the pack to follow it. &lt;a href="https://6866466570918.gumroad.com/l/python?utm_source=dev&amp;amp;utm_medium=organic&amp;amp;utm_campaign=stop_copying_ai_fixes&amp;amp;utm_content=dev-01" rel="noopener noreferrer"&gt;See the pack and decide whether it fits your practice&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Disclosure: I sell the pack mentioned here. This article was prepared with AI assistance, and the code example and results were checked as described above.&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>python</category>
    </item>
  </channel>
</rss>
