From 0e4f050abbb24c486bc8ef8cf6c1a8f4947cf34e Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Wed, 28 Aug 2019 07:07:30 +0200 Subject: [PATCH] Add hashing methods to XSD datatypes classes --- CHANGELOG.rst | 5 +++++ README.rst | 2 +- doc/conf.py | 2 +- elementpath/__init__.py | 2 +- elementpath/datatypes.py | 15 ++++++++++++--- publiccode.yml | 2 +- setup.py | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aad4405..a8355ab 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ CHANGELOG ********* +`v1.2.1`_ (TBD) +=============== +* Hashable XSD datatypes classes + `v1.2.0`_ (2019-08-14) ====================== * Added special XSD datatypes @@ -142,3 +146,4 @@ CHANGELOG .. _v1.1.8: https://github.com/brunato/elementpath/compare/v1.1.7...v1.1.8 .. _v1.1.9: https://github.com/brunato/elementpath/compare/v1.1.8...v1.1.9 .. _v1.2.0: https://github.com/brunato/elementpath/compare/v1.1.9...v1.2.0 +.. _v1.2.1: https://github.com/brunato/elementpath/compare/v1.2.0...v1.2.1 diff --git a/README.rst b/README.rst index e3259c0..b936c90 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ because `lxml.etree `_ already has it's own implementation of XP Installation and usage ====================== -You can install the package with *pip* in a Python 2.7 or Python 3.4+ environment:: +You can install the package with *pip* in a Python 2.7 or Python 3.5+ environment:: pip install elementpath diff --git a/doc/conf.py b/doc/conf.py index ac2a2bd..6be8790 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -31,7 +31,7 @@ author = 'Davide Brunato' # The short X.Y version version = '1.2' # The full version, including alpha/beta/rc tags -release = '1.2.0' +release = '1.2.1' # -- General configuration --------------------------------------------------- diff --git a/elementpath/__init__.py b/elementpath/__init__.py index d0e1fec..293df00 100644 --- a/elementpath/__init__.py +++ b/elementpath/__init__.py @@ -8,7 +8,7 @@ # # @author Davide Brunato # -__version__ = '1.2.0' +__version__ = '1.2.1' __author__ = "Davide Brunato" __contact__ = "brunato@sissa.it" __copyright__ = "Copyright 2018-2019, SISSA" diff --git a/elementpath/datatypes.py b/elementpath/datatypes.py index cb7d318..0ad39eb 100644 --- a/elementpath/datatypes.py +++ b/elementpath/datatypes.py @@ -130,15 +130,15 @@ class Timezone(datetime.tzinfo): def __getinitargs__(self): return self.offset, + def __hash__(self): + return hash(self.offset) + def __eq__(self, other): return isinstance(other, Timezone) and self.offset == other.offset def __ne__(self, other): return not isinstance(other, Timezone) or self.offset != other.offset - def __hash__(self): - return hash(self.offset) - def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.offset) @@ -345,6 +345,9 @@ class AbstractDateTime(object): else: raise ElementPathTypeError("wrong type %r for operand %r." % (type(other), other)) + def __hash__(self): + return hash((self._dt, self._year)) + def __eq__(self, other): try: return operator.eq(*self._get_operands(other)) and self.year == other.year @@ -815,6 +818,9 @@ class Duration(object): datetime.timedelta(months2days(1903, 7, m2), s2, ms2)), ]) + def __hash__(self): + return hash((self.months, self.seconds)) + def __eq__(self, other): if isinstance(other, self.__class__): return self.months == other.months and self.seconds == other.seconds @@ -951,6 +957,9 @@ class UntypedAtomic(object): else: return type(other)(self.value), other + def __hash__(self): + return hash(self.value) + def __eq__(self, other): return operator.eq(*self._get_operands(other, force_float=False)) diff --git a/publiccode.yml b/publiccode.yml index 6690201..62db2ea 100644 --- a/publiccode.yml +++ b/publiccode.yml @@ -37,7 +37,7 @@ it: riuso: codiceIPA: sissa piattaforme: - spid: true + spid: false description: en: genericName: elementpath diff --git a/setup.py b/setup.py index 7904dc3..6f4fb9a 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ with open("README.rst") as readme: setup( name='elementpath', - version='1.2.0', + version='1.2.1', packages=['elementpath'], author='Davide Brunato', author_email='brunato@sissa.it',