From 462af2b3da4ea1f45afbb5cb7facdeb236efdac3 Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Fri, 17 Jun 2016 12:06:52 +0200 Subject: [PATCH] Python API: add __eq__ and __hash__ to analysis context/unit classes So that different Python wrapper for the same analysis context/unit behave more like a single one: only identity (id(obj)) should differ. Change-Id: I94ca1e978081b074c0050fa4dae0931985b2659c TN: P407-015 --- langkit/templates/python_api/module_py.mako | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/langkit/templates/python_api/module_py.mako b/langkit/templates/python_api/module_py.mako index 4b12894c5..2c9f6a316 100644 --- a/langkit/templates/python_api/module_py.mako +++ b/langkit/templates/python_api/module_py.mako @@ -149,6 +149,12 @@ class AnalysisContext(object): _destroy_analysis_context(self._c_value) super(AnalysisContext, self).__init__() + def __eq__(self, other): + return self._c_value == other._c_value + + def __hash__(self): + return hash(self._c_value) + def get_from_file(self, filename, charset=None, reparse=False, with_trivia=False): ${py_doc('langkit.get_unit_from_file', 8)} @@ -224,6 +230,12 @@ class AnalysisUnit(object): _unit_decref(self._c_value) super(AnalysisUnit, self).__init__() + def __eq__(self, other): + return self._c_value == other._c_value + + def __hash__(self): + return hash(self._c_value) + def reparse(self, buffer=None, charset=None): ${py_doc('langkit.unit_reparse_generic', 8)} if buffer is None: