Created
January 14, 2026 22:00
-
-
Save mypy-play/dd0214051d0571c0ac920271a1ac4193 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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