Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created January 14, 2026 22:00
Show Gist options
  • Select an option

  • Save mypy-play/dd0214051d0571c0ac920271a1ac4193 to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/dd0214051d0571c0ac920271a1ac4193 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
import ast
class ComparisonSwapper(ast.NodeTransformer):
OP_MAP = {
ast.Lt: ast.GtE,
ast.GtE: ast.Lt,
}
def visit_Compare(self, node: ast.AST) -> ast.AST:
new_ops = [self.OP_MAP.get(type(op), type(op))() for op in node.ops]
node.ops = new_ops
return node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment