Skip to content

Commit 20b8758

Browse files
committed
-
1 parent 24ac4cd commit 20b8758

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

source_py2/python_toolbox/combi/perm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def __call__(cls, item, perm_space=None):
5353

5454

5555
@functools.total_ordering
56-
class Perm(sequence_tools.CuteSequenceMixin, collections.Sequence,
57-
metaclass=PermType):
56+
class Perm(sequence_tools.CuteSequenceMixin, collections.Sequence):
57+
58+
__metaclass__ = PermType
5859

5960
@classmethod
6061
def coerce(cls, item, perm_space=None):

source_py2/python_toolbox/combi/perm_space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def __call__(cls, *args, **kwargs):
5656

5757

5858
@functools.total_ordering
59-
class PermSpace(sequence_tools.CuteSequenceMixin, collections.Sequence,
60-
metaclass=PermSpaceType):
59+
class PermSpace(sequence_tools.CuteSequenceMixin, collections.Sequence)
6160
'''
6261
A space of permutations on a sequence.
6362
@@ -109,6 +108,7 @@ class PermSpace(sequence_tools.CuteSequenceMixin, collections.Sequence,
109108
110109
Some clarification on terminology <blocktododoc> rapplied, dapplied "just" etc.
111110
'''
111+
__metaclass__ = PermSpaceType
112112

113113
@classmethod
114114
def coerce(cls, argument):

source_py2/python_toolbox/math_tools/types.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ class _PossiblyInfiniteIntegralType(abc.ABCMeta):
1212
# blocktodo: use everywhere in python_toolbox
1313
def __instancecheck__(self, thing):
1414
return isinstance(thing, numbers.Integral) or (thing in infinities)
15-
class PossiblyInfiniteIntegral(numbers.Number,
16-
metaclass=_PossiblyInfiniteIntegralType):
17-
pass
15+
class PossiblyInfiniteIntegral(numbers.Number):
16+
__metaclass__ = _PossiblyInfiniteIntegralType
1817

1918
class _PossiblyInfiniteRealType(abc.ABCMeta):
2019
# blocktodo: use everywhere in python_toolbox
2120
def __instancecheck__(self, thing):
2221
return isinstance(thing, numbers.Real) or (thing in infinities)
23-
class PossiblyInfiniteReal(numbers.Number,
24-
metaclass=_PossiblyInfiniteRealType):
25-
pass
22+
class PossiblyInfiniteReal(numbers.Number):
23+
__metaclass__ = _PossiblyInfiniteRealType
2624

2725

source_py2/python_toolbox/sequence_tools/cute_range.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import builtins
32
import types
43
import collections
54
import numbers
@@ -77,7 +76,11 @@ def _is_integral_or_none(thing):
7776

7877
class CuteRangeType(abc.ABCMeta):
7978
'''Metaclass for `CuteRange`, see its docstring for details.'''
80-
def __call__(cls, *args, _avoid_built_in_range=False):
79+
def __call__(cls, *args, **kwargs):
80+
81+
_avoid_built_in_range = kwargs.pop('_avoid_built_in_range', False)
82+
assert not kwargs
83+
8184
# Our job here is to decide whether to instantiate using the built-in
8285
# `range` or our kickass `Range`.
8386
from python_toolbox import math_tools
@@ -107,7 +110,7 @@ def __call__(cls, *args, _avoid_built_in_range=False):
107110
return super().__call__(*args)
108111

109112

110-
class CuteRange(CuteSequence, metaclass=CuteRangeType):
113+
class CuteRange(CuteSequence):
111114
'''
112115
Improved version of Python's `range` that has extra features.
113116
@@ -121,6 +124,9 @@ class CuteRange(CuteSequence, metaclass=CuteRangeType):
121124
122125
123126
'''
127+
128+
__metaclass__ = CuteRangeType
129+
124130
def __init__(self, *args):
125131
self.start, self.stop, self.step = parse_range_args(*args)
126132

source_py2/python_toolbox/sequence_tools/misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def combinations(sequence, n=None, start=0):
6767
length = len(sequence) - start
6868
iterators = (combinations(sequence, n=i, start=start) for i
6969
in range(1, length + 1))
70-
yield from itertools.chain(*iterators)
70+
for thing in itertools.chain(*iterators):
71+
yield thing
7172

7273
elif n == 1:
7374
for thing in itertools.islice(sequence, start, None):

0 commit comments

Comments
 (0)