Commits

Lynn Rees committed 2a8a843

- extend coverage

  • Participants
  • Parent commits 3c9c549
  • Branches next

Comments (0)

Files changed (8)

File twoq/active/mixins.py

 from collections import deque
 from contextlib import contextmanager
 
+from stuf.utils import clsname
+
 from twoq.queuing import ThingsMixin, ResultMixin
 
 
             'OUT: {}: ({})]) at {}'
         ).format(
             self.__module__,
-            self._clsname(self),
+            clsname(self),
             self._INQ,
             list_(getr_(self._INQ)),
             self._WORKQ,

File twoq/filtering.py

 # -*- coding: utf-8 -*-
 '''twoq filtering mixins'''
 
-from itertools import tee, islice
 from inspect import getmro
 from threading import local
 from functools import reduce
-
+from itertools import tee, islice
 from operator import attrgetter, itemgetter, truth
 
-from stuf.six import PY3
 from stuf.utils import getcls
 
 from twoq.support import ifilter, ichain, imap, filterfalse
         @param truth: second "Truth" filter
         @param iterable: an iterable
         '''
-        def members(
-            f, s, t, i, d_=dir, w_=cls._extract, g=getattr, e=AttributeError,
-        ): #@IgnorePep8
-            for k in d_(i):
+        def members():
+            f, s, t, i = truth, subcall, transform, iterable
+            d, w, g, e = dir, cls._extract, getattr, AttributeError
+            test = lambda x: x.startswith('__') or x.startswith('mro')
+            for k in filterfalse(test, d(i)):
                 try:
                     v = g(i, k)
                 except e:
                     pass
                 else:
                     if s(v):
-                        yield k, t(w_(f, s, t, v))
+                        yield k, t(w(f, s, t, v))
                     else:
                         yield k, v
         for member in ifilter(
-            truth, members(truth, subcall, transform, iterable),
+            truth, members(),
         ):
             yield member
 
         @param call: "Truth" filter
         @param iterable: an iterable
         '''
-        def members(iterable):
-            getattr_, AttributeError_ = getattr, AttributeError
-            for key in dir(iterable):
+        def members(): #@IgnorePep8
+            itrbl, get_, AttributeError_ = iterable, getattr, AttributeError
+            test = lambda x: x.startswith('__') or x.startswith('mro')
+            for key in filterfalse(test, dir(iterable)):
                 try:
-                    thing = getattr_(iterable, key)
+                    thing = get_(itrbl, key)
                 except AttributeError_:
                     pass
                 else:
                     yield key, thing
-        for i in ifilter(call, members(iterable)):
+        for i in ifilter(call, members()):
             yield i
 
     @staticmethod
         '''collect object members from incoming things and their bases'''
         _mf = self._mfilter
         _mz = lambda x: _mf(self._call, x)
-        if PY3:
-            def _memfilters(thing, mz=_mz, gc=getcls, ci=ichain):
-                t = lambda x: not x[0].startswith('mro')
-                return self._ifilter(
-                    t, ci(imap(mz, ci([getmro((gc(thing))), [thing]])))
-                )
-        else:
-            def _memfilters(thing, mz=_mz, gc=getcls, ci=ichain):
-                return ci(imap(mz, ci([getmro((gc(thing))), [thing]])))
+        def _memfilters(thing, mz=_mz, gc=getcls, ci=ichain):
+            return ci(imap(mz, ci([getmro((gc(thing))), [thing]])))
         with self._context():
             return self._xtend(
                 ichain(imap(_memfilters, self._iterable))
     def members(self):
         '''collect object members from incoming things'''
         with self._context():
-            mfilter = self._mfilter
+            mfilter, call = self._mfilter, self._call
             return self._xtend(ichain(imap(
-                lambda x: mfilter(self._call, x), self._iterable,
+                lambda x: mfilter(call, x), self._iterable,
             )))
 
     def pick(self, *names):
         @param key: determine uniqueness filter
         '''
         seen = set()
-        seen_add_, seen_contains_ = seen.add, seen.__contains__
-        if key is None:
-            for element in filterfalse(seen_contains_, iterable):
-                seen_add_(element)
+        seen_add_ = seen.add
+        key_ = key
+        for element in iterable:
+            k = key_(element)
+            if k not in seen:
+                seen_add_(k)
                 yield element
-        else:
-            for element in iterable:
-                k = key(element)
-                if k not in seen:
-                    seen_add_(k)
-                    yield element
 
     def difference(self):
         '''difference between incoming things'''

File twoq/lazy/mixins.py

 from itertools import tee, chain
 from contextlib import contextmanager
 
+from stuf.utils import clsname
+
 from twoq.queuing import ResultMixin, ThingsMixin
 
 __all__ = ('AutoQMixin', 'ManQMixin', 'AutoResultMixin', 'ManResultMixin')
             'OUT: {}: ({})]) at {}>'
         ).format(
             self.__module__,
-            self._clsname(self),
+            clsname(self),
             self._INQ,
             list_(in2),
             self._WORKQ,

File twoq/ordering.py

         '''
         call_, list_ = self._call, list
         with self._context():
-            if call_ is None:
-                return self._xtend(imap(
-                    lambda x: [x[0], list_(x[1])], groupby(self._iterable),
-                ))
             return self._xtend(imap(
                 lambda x: [x[0], list_(x[1])], groupby(self._iterable, call_)
             ))
         '''
         call_ = self._call
         with self._context():
-            if call_ is None:
-                return self._xtend(sorted(self._iterable))
             return self._xtend(sorted(self._iterable, key=call_))
 
 

File twoq/queuing.py

 
 from threading import local
 from collections import deque
-from itertools import tee, starmap, repeat
+from itertools import tee, repeat
 from contextlib import contextmanager
 
-from support import ifilter, items
-
 
 class ThingsMixin(local):
 
                 pass
 
     @staticmethod
-    def iterexcept(call, exception, start=None):
+    def iterexcept(call, exception):
         '''
         call a function repeatedly until an exception is raised
 
         Raymond Hettinger, Python Cookbook recipe # 577155
         '''
         try:
-            if start is not None:
-                yield start()
             while 1:
                 yield call()
         except exception:
             pass
 
-    ###########################################################################
-    ## exhaustion iterators ###################################################
-    ###########################################################################
-
-    def exhaust(self, iterable, exception=StopIteration):
-        '''
-        call next on an iterator until it's exhausted
-
-        @param iterable: iterable to exhaust
-        @param exception: exception marking end of iteration
-        '''
-        next_ = next
-        try:
-            while 1:
-                next_(iterable)
-        except exception:
-            pass
-
-    def exhaustcall(self, call, iterable, exception=StopIteration):
-        '''
-        call function on an iterator until it's exhausted
-
-        @param call: call that does the exhausting
-        @param iterable: iterable to exhaust
-        @param exception: exception marking end of iteration
-        '''
-        next_ = self._next
-        iterable = self._imap(call, iterable)
-        try:
-            while 1:
-                next_(iterable)
-        except exception:
-            pass
-        return self
-
-    def exhaustitems(self, maps, call, filter=False, exception=StopIteration):
-        '''
-        call `next` on an iterator until it's exhausted
-
-        @param mapping: a mapping to exhaust
-        @param call: call to handle what survives the filter
-        @param filter: a filter to apply to mapping (default: `None`)
-        @param exception: exception sentinel (default: `StopIteration`)
-        '''
-        next_ = next
-        iterable = starmap(
-            call, ifilter(filter, items(maps)) if filter else items(maps)
-        )
-        try:
-            while 1:
-                next_(iterable)
-        except exception:
-            pass
-        return self
-
 
 class ResultMixin(local):
 
     '''result things mixin'''
 
-    def end(self):
-        '''return outgoing things then clear out everything'''
-        # return to default context
-        self.unswap()
-        out, tell = tee(self.outgoing)
-        wrap = self._wrapper
-        out = next(out) if len(wrap(tell)) == 1 else wrap(out)
-        # clear every last thing
-        self.clear()
-        return out
-
     def first(self):
         '''first incoming thing'''
         with self._context():
     def results(self):
         '''yield outgoing things, clearing outgoing things as it iterates'''
         return self.__iter__()
-
-    def value(self):
-        '''return outgoing things and clear outgoing things'''
-        # return to default context
-        self.unswap()
-        out, tell = tee(self.outgoing)
-        wrap = self._wrapper
-        out = next(out) if len(wrap(tell)) == 1 else wrap(out)
-        # clear outgoing things
-        self.outclear()
-        return out

File twoq/reducing.py

 from math import fsum
 from heapq import merge
 from threading import local
-from functools import partial
 from collections import Iterable
+from functools import partial, reduce
 from operator import contains, truediv
 from itertools import cycle, tee, islice
 
         find maximum thing in incoming things, optionally using current
         call as key function
         '''
-        call = self._call
         with self._context():
-            if call is None:
-                return self._append(max(self._iterable))
-            return self._append(max(self._iterable, key=call))
+            return self._append(max(self._iterable, key=self._call))
 
     def median(self):
         '''median of all incoming things'''
 
     def min(self):
         '''find minimum thing in incoming things using call as key function'''
-        call = self._call
         with self._context():
-            if call is None:
-                return self._append(min(self._iterable))
-            return self._append(min(self._iterable, key=call))
+            return self._append(min(self._iterable, key=self._call))
 
     def minmax(self):
         '''minimum and maximum things among all incoming things'''

File twoq/tests/auto/queuing.py

     ## queue manipulation #####################################################
     ###########################################################################
 
+    def test_repr(self):
+        from stuf.six import strings
+        self.assertTrue(isinstance(
+            self.qclass([1, 2, 3, 4, 5, 6]).__repr__(), strings,
+        ))
+
     def test_ro(self):
         self.assertListEqual(
             self.qclass([1, 2, 3, 4, 5, 6]).ro().peek(), [1, 2, 3, 4, 5, 6],

File twoq/tests/man/queuing.py

     ## queue manipulation #####################################################
     ###########################################################################
 
+    def test_repr(self):
+        from stuf.six import strings
+        self.assertTrue(isinstance(
+            self.qclass([1, 2, 3, 4, 5, 6]).__repr__(), strings,
+        ))
+
     def test_ro(self):
         self.assertEqual(
             self.qclass([1, 2, 3, 4, 5, 6]).ro().peek(), [1, 2, 3, 4, 5, 6],