From 489d5c4b5f662971cf8cd03fe4580bd90fb4f36d Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Fri, 30 May 2008 11:14:35 +0200 Subject: [PATCH] Added eq and hash to source descriptors --- Cython/Compiler/Scanning.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.26.2