[Python-checkins] r53083 - in sandbox/trunk/2to3: example.py fixes/fix_ne.py

guido.van.rossum python-checkins at python.org
Tue Dec 19 22:03:16 CET 2006


Author: guido.van.rossum
Date: Tue Dec 19 22:03:16 2006
New Revision: 53083

Added:
   sandbox/trunk/2to3/fixes/fix_ne.py   (contents, props changed)
Modified:
   sandbox/trunk/2to3/example.py
Log:
Add a fixer that turns <> into !=.  Sorry, Barry!


Modified: sandbox/trunk/2to3/example.py
==============================================================================
--- sandbox/trunk/2to3/example.py	(original)
+++ sandbox/trunk/2to3/example.py	Tue Dec 19 22:03:16 2006
@@ -3,6 +3,14 @@
 """Docstring."""
 import sys
 
+def ne_examples():
+    if x <> y:
+        pass
+    if x<>y:
+        pass
+    if x<>y<>z:
+        pass
+
 def has_key_examples():
     #
     x = d.has_key("x") or d.has_key("y")

Added: sandbox/trunk/2to3/fixes/fix_ne.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/fixes/fix_ne.py	Tue Dec 19 22:03:16 2006
@@ -0,0 +1,30 @@
+# Copyright 2006 Google, Inc. All Rights Reserved.
+# Licensed to PSF under a Contributor Agreement.
+
+"""Fixer that turns <> into !=.
+
+This is so simple that we don't need the pattern compiler.
+"""
+
+# Python imports
+import token
+
+# Local imports
+import pytree
+import pygram
+
+syms = pygram.python_symbols
+
+
+class FixNe(object):
+
+    def __init__(self, options):
+        self.options = options
+
+    def match(self, node):
+        return node.type == token.NOTEQUAL and node.value == "<>"
+
+    def transform(self, node):
+      new = pytree.Leaf(token.NOTEQUAL, "!=")
+      new.set_prefix(node.get_prefix())
+      return new


More information about the Python-checkins mailing list