Commits

Jonathan Eunice  committed 154cea0

minor cleanups; primarily comments

  • Participants
  • Parent commits 5c534ec

Comments (0)

Files changed (4)

 
     t1 = Thing("one")
     t2 = Thing("one")
-    assert t1 is t2
+    assert t1 is t2    # same instantiation args => same object
     
 Python 3
 ========
     class Thing23(with_metaclass(MementoMetaclass, object)):
         ...
 
-alternatively you can import it from the ``six`` module::
-
-    from six import with_metaclass
-    ...
-    
-(You could even inline what ``with_metaclass()`` does directly, but it's
-really ugly, hard-to-read, and not recommended.)
+alternatively you can import it from the ``six`` module.
+You could even inline what ``with_metaclass()`` does directly, but it's
+really ugly, hard-to-read, and not recommended.
 
 Careful with Call Signatures
 ============================
 MementoMetaclass = memento_factory("MementoMetaclass",
                                    lambda cls, args, kwargs: (cls, ) + args + tuple(kwargs.items()) )
 
-# 
+
 # Some reading:
 # http://bytes.com/topic/python/answers/40084-parameterized-metaclass-metametaclass
 # http://www.acooke.org/cute/PythonMeta0.html
 
 setup(
     name='mementos',
-    version=verno("0.452"),
+    version=verno("0.457"),
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='Memoizing metaclass. Drop-dead simple way to create cached objects',

File test/test.py

     
     from inspect import getcallargs
     import hashlib
-    import six
     
     def call_fingerprint(cls, args, kwargs):
         """
-        Given a complex __init__ call with varied positional, keyward, variable, and
-        variable keyword arguments, canonicalize the argument values and return a
-        suitable hash key.
+        Given a complex __init__ call with varied positional, keyward, variable,
+        and variable keyword arguments, canonicalize the argument values and
+        return a suitable hash key. NB this is suitable for cases where it is
+        primarily the use of default values and keyword specification of args
+        that might otherwise be given positionally that causes key signatures to
+        vary, and in which the primary args (ie, not * or ** values) are simple
+        scalars.
+        
+        In cases where objects or dicts may be passed, or * and ** values are
+        used, a deep recursive flattening and sorting of values and key/value
+        pairs must be done. This 1% of the 1% use case is beyond the scope here.
         """
-        callitems = list(getcallargs(cls.__init__, None, *args, **kwargs).items())
+        callargs = getcallargs(cls.__init__, None, *args, **kwargs)
+        callitems = list(callargs.items())
         callitems.sort()
         h = hashlib.md5()
         h.update(repr(callitems).encode('utf-8'))