1. Jonathan Eunice
  2. intensional

Commits

Jonathan Eunice  committed 6030a56

updated hashing strategy

  • Participants
  • Parent commits c3d663b
  • Branches default

Comments (0)

Files changed (3)

File intensional/core.py

View file
  • Ignore whitespace
 
-from mementos import MementoMetaclass   # to memoize IntensionalSet
+from mementos import memento_factory, with_metaclass
+                                        # to memoize IntensionalSet
 import re                               # for Re
 import fnmatch                          # for Glob
 # import six
 import sys, copy
 import collections
+from intensional.superhash import superhash
 
 if sys.version_info[0] > 2:
     unicode = str
     basestring = str
 
-def with_metaclass(meta, base=object):
-    """Create a base class with a metaclass."""
-    return meta("NewBase", (base,), {})
+SuperHashMeta = memento_factory('SuperHashMeta',
+                            lambda cls, args, kwargs: (cls, superhash(args)) )
 
 class IntensionalSet(object):
     """
     def __getitem__(self, index):
         return self._match.group(index)
 
-class Re(with_metaclass(MementoMetaclass, IntensionalSet)):
+class Re(with_metaclass(SuperHashMeta, IntensionalSet)):
     
     # convenience copy of re flag constants
     
     def escape(self, *args, **kwargs):
         return self.re.escape(*args, **kwargs)
 
-class Glob(with_metaclass(MementoMetaclass, IntensionalSet)):
+class Glob(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An item matches a Glob via Unix filesystem glob semantics.
     
     def __contains__(self, item):
         return fnmatch.fnmatch(str(item), self.pattern)
 
-class Instances(with_metaclass(MementoMetaclass, IntensionalSet)):
+class Instances(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An object is in an IsInstance if it is an instance of the given types.
     """
     return False
 
     
-class Any(IntensionalSet):
+class Any(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An item is in an Any if it is or is in any member of the set.
     """
                 return True
         return False
     
-class Every(IntensionalSet):
+class Every(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An item is in an Every if it is or is in every member of the set.
     """
                 return False
         return True
 
-class ButNot(IntensionalSet):
+class ButNot(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An item is in a ButNot if it's in the primary set and not the exclusion.
     """
     
     # probably need to guard against type errors here
     
-class EitherOr(IntensionalSet):
+class EitherOr(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     An item is in an EitherOr if it's in subseta or subset b, but not both.
     """
         else:
             return False
         
-class Test(IntensionalSet):
+class Test(with_metaclass(SuperHashMeta, IntensionalSet)):
     """
     Test is a generic wrapper around lambda expressions.
     Provides special support for compact, neat expressions by not

File setup.py

View file
  • Ignore whitespace
 
 setup(
     name='intensional',
-    version=verno("0.204"),
+    version=verno("0.216"),
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='Intensional sets in Python',
     long_description=open('README.rst').read(),
     url='https://bitbucket.org/jeunice/intensional',
     packages=['intensional'],
-    install_requires=['stuf>=0.9.10','mementos>=0.45'],
+    install_requires=['stuf>=0.9.10','mementos>=0.5'],
     tests_require = ['tox', 'pytest'],
     zip_safe = True,
     keywords='intensional sets lambda expression list comprehension',

File test/test.py

View file
  • Ignore whitespace
     in_out(any2,
           [1,2,3, "this", "that"],
           [44, 45, 'lovely', 'bones'])
+    
+    assert Any(1,2,3,"this") is Any(1,2,3,"this")
 
     
 def test_Every():
     assert 55 in e2
     assert 0 not in e2
     assert 18 not in e2
-    
+
     e3 = Every(Test('x.startswith("r")'), Test('len(x) <= 5'))
     
     assert 'roger' in e3
     assert 'roof'  in e3b
     assert 'roofer' not in e3b
     
+    assert Every(1,2,3,"this") is Every(1,2,3,"this")
+    
     # any way to link to Python all and any?
 
 def test_ButNot():
     assert 12 in a2
     assert 12 not in bn
     
+    assert ButNot(Any(12, Test('x.startswith("k")')), Any(12, 'kookoo')) is \
+           ButNot(Any(12, Test('x.startswith("k")')), Any(12, 'kookoo'))
+    
+    
 def test_union():
     a = Any(44, Test('x < 12'))
     b = Test('x > 100')