From: Dag Sverre Seljebotn Date: Fri, 30 May 2008 09:14:35 +0000 (+0200) Subject: Added eq and hash to source descriptors X-Git-Tag: 0.9.8rc1~11^2~10^2~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=489d5c4b5f662971cf8cd03fe4580bd90fb4f36d;p=cython.git Added eq and hash to source descriptors --- diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 6aacb8fa..4ba1718c 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -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 "" % 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 "" % self.name