Added eq and hash to source descriptors
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 30 May 2008 09:14:35 +0000 (11:14 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 30 May 2008 09:14:35 +0000 (11:14 +0200)
Cython/Compiler/Scanning.py

index 6aacb8faf263a30816d28908550dbb18fc4e46dc..4ba1718c7d4ca87903acf273021ff9a73d8f711d 100644 (file)
@@ -206,6 +206,9 @@ def initial_compile_time_env():
 #------------------------------------------------------------------
 
 class SourceDescriptor:
+    """
+    A SourceDescriptor should be considered immutable.
+    """
     def __str__(self):
         assert False # To catch all places where a descriptor is used directly as a filename
 
@@ -237,6 +240,12 @@ class FileSourceDescriptor(SourceDescriptor):
     def get_filenametable_entry(self):
         return self.filename
     
+    def __eq__(self, other):
+        return isinstance(other, FileSourceDescriptor) and self.filename == other.filename
+
+    def __hash__(self):
+        return hash(self.filename)
+
     def __repr__(self):
         return "<FileSourceDescriptor:%s>" % self.filename
 
@@ -258,6 +267,12 @@ class StringSourceDescriptor(SourceDescriptor):
     def get_filenametable_entry(self):
         return "stringsource"
 
+    def __hash__(self):
+        return hash(self.name)
+
+    def __eq__(self, other):
+        return isinstance(other, StringSourceDescriptor) and self.name == other.name
+
     def __repr__(self):
         return "<StringSourceDescriptor:%s>" % self.name