<?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: khanhnam-nathan</title>
    <description>The latest articles on DEV Community by khanhnam-nathan (@khanhnamnathan).</description>
    <link>https://dev.to/khanhnamnathan</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%2F3860551%2F9caab371-2ec9-4401-8249-3b75c102b686.png</url>
      <title>DEV Community: khanhnam-nathan</title>
      <link>https://dev.to/khanhnamnathan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khanhnamnathan"/>
    <language>en</language>
    <item>
      <title>I got tired of structural anti-patterns, so I built an AST-based code cleaner for Python 🧹</title>
      <dc:creator>khanhnam-nathan</dc:creator>
      <pubDate>Sat, 04 Apr 2026 06:36:54 +0000</pubDate>
      <link>https://dev.to/khanhnamnathan/i-got-tired-of-structural-anti-patterns-so-i-built-an-ast-based-code-cleaner-for-python-1mnf</link>
      <guid>https://dev.to/khanhnamnathan/i-got-tired-of-structural-anti-patterns-so-i-built-an-ast-based-code-cleaner-for-python-1mnf</guid>
      <description>&lt;p&gt;Hi DEV community! 👋&lt;/p&gt;

&lt;p&gt;I spend a lot of time reviewing Python code. I noticed that while formatters (like Black or Ruff) are amazing at fixing styling and whitespaces, they don't fix structural logic flaws.&lt;/p&gt;

&lt;p&gt;If you have a deeply nested if/else block (the Arrow Anti-pattern), or a dangerous eval(), standard formatters will just make that bad logic look pretty.&lt;/p&gt;

&lt;p&gt;So, I decided to build PyNeat — a CLI tool based on Instagram's LibCST to perform deep structural refactoring.&lt;/p&gt;

&lt;p&gt;🚀 What PyNeat Does&lt;br&gt;
PyNeat scans your Python AST in a single pass and automatically refactors anti-patterns. Unlike the built-in ast module, because it uses LibCST, it preserves 100% of your original comments and whitespace.&lt;/p&gt;

&lt;p&gt;Currently, the v1.0 MVP fixes:&lt;/p&gt;

&lt;p&gt;The Arrow Anti-pattern: Flattens deeply nested if/else using guard clauses.&lt;/p&gt;

&lt;p&gt;Dangerous Evals: Safely converts eval() to AST literals.&lt;/p&gt;

&lt;p&gt;Empty Excepts: Detects silent except: pass failures.&lt;/p&gt;

&lt;p&gt;Mutable Defaults: Fixes the infamous def func(items=[]) memory leak.&lt;/p&gt;

&lt;p&gt;Identity Checks: Upgrades == None to is None.&lt;/p&gt;

&lt;p&gt;💡 The Roadmap&lt;br&gt;
It is still in its early MVP stage! I've already received some great feedback from Reddit about handling edge cases (like import hoisting), and I'm actively working on a robust pytest suite. The ultimate goal is a Rust rewrite (pyneat-rs) for massive multi-threading performance.&lt;/p&gt;

&lt;p&gt;Links:&lt;/p&gt;

&lt;p&gt;🐙 GitHub: &lt;a href="https://github.com/khanhnam-nathan/Pyneat" rel="noopener noreferrer"&gt;https://github.com/khanhnam-nathan/Pyneat&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📦 PyPI: pip install pyneat-cli&lt;/p&gt;

&lt;p&gt;I would love to hear your thoughts! Have you ever struggled with writing structural refactoring tools? Any feedback on the architecture would be deeply appreciated!&lt;/p&gt;

</description>
      <category>python</category>
      <category>showdev</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
