agent_docs/code-simplification.md
Rules for simplifying code using Python idioms, comprehensions, operators, and eliminating unnecessary complexity
When to check: When refactoring code for clarity or looking to simplify complex patterns
_filtered, _copy, etc. — Reduces noise and indirection, making data flow clearer and eliminating unnecessary names that don't add semantic value.if statements with no intervening code into if condition1 and condition2: — Reduces nesting depth and improves readability without changing logicisinstance() checks, not | union — tuples are faster at runtime — Runtime performance optimization: tuple syntax avoids the overhead of union type creationTypeAdapter instances at module level as constants — avoids repeated initialization overhead — Creating TypeAdapters repeatedly inside functions or loops wastes CPU cycles on redundant schema construction that only needs to happen once.any() instead of for-loops with boolean flags when checking if any element matches a condition — More concise and Pythonic; eliminates manual flag management and break statements, reducing potential for logic errors@cached_property for expensive computed attributes — defers computation until first access and caches the result — Improves startup performance by avoiding unnecessary computation and reduces memory overhead when attributes may not be usedx or default for fallback values instead of verbose if-else blocks — more concise and idiomatic — This pattern is shorter and clearer for typical fallback logic, but avoid it when falsy values (0, '', [], None) are semantically valid and shouldn't trigger the default