Skip to content

Commit 6ddd02c

Browse files
committed
-
1 parent ed7aa57 commit 6ddd02c

File tree

13 files changed

+20
-23
lines changed

13 files changed

+20
-23
lines changed

source_py2/python_toolbox/cute_iter_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def make_false_iterator():
258258
return (make_true_iterator(), make_false_iterator())
259259

260260

261-
261+
262262
def get_ratio(filter_function, iterable):
263263
'''Get the ratio of `iterable` items that pass `filter_function`.'''
264264
if isinstance(filter_function, str):
@@ -272,7 +272,7 @@ def get_ratio(filter_function, iterable):
272272
n_passed_items += 1
273273
return n_passed_items / n_total_items
274274

275-
275+
276276
def fill(iterable, fill_value=None, fill_value_maker=None, length=infinity,
277277
sequence_type=None):
278278
'''

source_py2/python_toolbox/cute_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def manage_context(self):
6262
'''Manage the `RaiseAssertor'`s context.'''
6363
try:
6464
yield self
65-
except self.exception_type, exception:
65+
except self.exception_type as exception:
6666
self.exception = exception
6767
if self.assert_exact_type:
6868
if self.exception_type is not type(exception):
@@ -89,7 +89,7 @@ def manage_context(self):
8989
if not self.text.match(message):
9090
raise Failure("A `%s` was raised but it didn't match "
9191
"the given regex." % self.exception_type)
92-
except BaseException, different_exception:
92+
except BaseException as different_exception:
9393
raise Failure(
9494
"%s was excpected, but a different exception %s was raised "
9595
"instead." % (self.exception_type, type(different_exception))

source_py2/python_toolbox/dict_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def show(thing, indent=0):
5656

5757
temp1 = (
5858
(big_space + repr(key) + ':\n' + huge_space + show(value, indent + 8))
59-
for(key, value) in d.items())
59+
for (key, value) in d.items())
6060

6161
temp2 = small_space + '{\n' + ',\n'.join(temp1) + '\n' + small_space +'}'
6262

@@ -108,7 +108,7 @@ def reverse_with_set_values(d, sort=False):
108108
if sort:
109109
from python_toolbox import nifty_collections
110110
ordered_dict = nifty_collections.OrderedDict(new_dict)
111-
if callable(sort) or isinstance(sort, basestring):
111+
if isinstance(sort, (collections.Callable, basestring)):
112112
key_function = comparison_tools. \
113113
process_key_function_or_attribute_name(sort)
114114
else:

source_py2/python_toolbox/math_tools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def get_mean(iterable):
8989
sum_ += value
9090
return sum_ / (i + 1)
9191

92-
9392

9493
def restrict_number_to_range(number, low_cutoff=-infinity,
9594
high_cutoff=infinity):
@@ -104,4 +103,4 @@ def restrict_number_to_range(number, low_cutoff=-infinity,
104103
return high_cutoff
105104
else:
106105
return number
107-
106+

source_py3/python_toolbox/arguments_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,13 @@ def __init__(self, function, *args, **kwargs):
363363
)
364364

365365
sorted_star_kwargs = OrderedDict(
366-
list(zip(
366+
zip(
367367
sorted_star_kwargs_names,
368368
dict_tools.get_list(
369369
getcallargs_result[s_star_kwargs],
370370
sorted_star_kwargs_names
371371
)
372-
))
372+
)
373373
)
374374

375375

source_py3/python_toolbox/comparison_tools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'''Defines various tools for comparisons.'''
55

66
import sys
7-
import collections
87

98

109
def underscore_hating_key(string):
@@ -67,7 +66,7 @@ def process_key_function_or_attribute_name(key_function_or_attribute_name):
6766
'''
6867
if key_function_or_attribute_name is None:
6968
return None
70-
elif isinstance(key_function_or_attribute_name, collections.Callable):
69+
elif callable(key_function_or_attribute_name):
7170
return key_function_or_attribute_name
7271
else:
7372
assert isinstance(key_function_or_attribute_name, str)

source_py3/python_toolbox/cute_iter_tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# todo: make something like `filter` except it returns first found, or raises
66
# exception
77

8-
9-
108
import collections
119
import itertools
1210
import builtins

source_py3/python_toolbox/dict_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def show(thing, indent=0):
5656

5757
temp1 = (
5858
(big_space + repr(key) + ':\n' + huge_space + show(value, indent + 8))
59-
for(key, value) in list(d.items()))
59+
for (key, value) in list(d.items()))
6060

6161
temp2 = small_space + '{\n' + ',\n'.join(temp1) + '\n' + small_space +'}'
6262

@@ -108,7 +108,7 @@ def reverse_with_set_values(d, sort=False):
108108
if sort:
109109
from python_toolbox import nifty_collections
110110
ordered_dict = nifty_collections.OrderedDict(new_dict)
111-
if isinstance(sort, collections.Callable) or isinstance(sort, str):
111+
if isinstance(sort, (collections.Callable, str)):
112112
key_function = comparison_tools. \
113113
process_key_function_or_attribute_name(sort)
114114
else:

source_py3/python_toolbox/function_anchoring_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __new__(mcls, name, bases, namespace_dict):
4141
my_getted_vars = misc_tools.getted_vars(my_type)
4242
# Repeat after me: "Getted, not dict."
4343

44-
functions_to_anchor = [value for key, value in list(my_getted_vars.items())
44+
functions_to_anchor = [value for key, value in my_getted_vars.items()
4545
if isinstance(value, types.FunctionType) and not
4646
misc_tools.is_magic_variable_name(key)]
4747
for function in functions_to_anchor:

source_py3/python_toolbox/import_tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import os.path
88
import imp
99
import zipimport
10+
import functools
1011

1112
from python_toolbox import package_finder
1213
from python_toolbox import caching
13-
from functools import reduce
1414

1515

1616

@@ -42,7 +42,7 @@ def import_all(package, exclude='__init__', silent_fail=False):
4242

4343
d = {}
4444

45-
for (path, name) in list(names.items()):
45+
for (path, name) in names.items():
4646
try:
4747
d[name] = normal_import(name)
4848
except Exception:
@@ -69,7 +69,8 @@ def normal_import(module_name):
6969
if '.' in module_name:
7070
package_name, submodule_name = module_name.rsplit('.', 1)
7171
package = __import__(module_name)
72-
return reduce(getattr, [package] + module_name.split('.')[1:])
72+
return functools.reduce(getattr,
73+
[package] + module_name.split('.')[1:])
7374
else:
7475
return __import__(module_name)
7576

0 commit comments

Comments
 (0)