提交 52843bcb authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Flake8 for gof/utils.py

上级 e0749882
from __future__ import print_function from __future__ import print_function
import linecache import linecache
import traceback import traceback
import re
import sys import sys
from theano import config from theano import config
...@@ -15,7 +14,6 @@ def simple_extract_stack(f=None, limit=None): ...@@ -15,7 +14,6 @@ def simple_extract_stack(f=None, limit=None):
This is because this update cause an call to os.stat to get the This is because this update cause an call to os.stat to get the
line content. This cause too much long on cluster. line content. This cause too much long on cluster.
""" """
if f is None: if f is None:
try: try:
...@@ -48,7 +46,7 @@ if sys.version_info[:2] > (3, 4): ...@@ -48,7 +46,7 @@ if sys.version_info[:2] > (3, 4):
# I enable my implementation only for some python version just to # I enable my implementation only for some python version just to
# be sure the Python internal do not change. If this work with # be sure the Python internal do not change. If this work with
# other python version, you can enable it. # other python version, you can enable it.
simple_extract_stack = traceback.extract_stack simple_extract_stack = traceback.extract_stack # noqa
def add_tag_trace(thing, user_line=1): def add_tag_trace(thing, user_line=1):
...@@ -81,7 +79,7 @@ def add_tag_trace(thing, user_line=1): ...@@ -81,7 +79,7 @@ def add_tag_trace(thing, user_line=1):
"theano/scan_module/", "theano/scan_module/",
"theano/sparse/", "theano/sparse/",
"theano/typed_list/", "theano/typed_list/",
]: ]:
if p in file_path: if p in file_path:
tr = tr[:-1] tr = tr[:-1]
rm = True rm = True
...@@ -190,8 +188,8 @@ def deprecated(filename, msg=''): ...@@ -190,8 +188,8 @@ def deprecated(filename, msg=''):
def g(*args, **kwargs): def g(*args, **kwargs):
if printme[0]: if printme[0]:
print('WARNING: %s.%s deprecated. %s'\ print('WARNING: %s.%s deprecated. %s' %
% (filename, f.__name__, msg)) (filename, f.__name__, msg))
printme[0] = False printme[0] = False
return f(*args, **kwargs) return f(*args, **kwargs)
return g return g
...@@ -220,7 +218,7 @@ def difference(seq1, seq2): ...@@ -220,7 +218,7 @@ def difference(seq1, seq2):
raise Exception('not worth it') raise Exception('not worth it')
set2 = set(seq2) set2 = set(seq2)
return [x for x in seq1 if x not in set2] return [x for x in seq1 if x not in set2]
except Exception as e: except Exception:
# maybe a seq2 element is not hashable # maybe a seq2 element is not hashable
# maybe seq2 is too short # maybe seq2 is too short
# -> use O(len(seq1) * len(seq2)) algo # -> use O(len(seq1) * len(seq2)) algo
...@@ -311,11 +309,11 @@ def comm_guard(type1, type2): ...@@ -311,11 +309,11 @@ def comm_guard(type1, type2):
old_f = f.func_globals[f.__name__] old_f = f.func_globals[f.__name__]
def new_f(arg1, arg2, *rest): def new_f(arg1, arg2, *rest):
if (type1 is ANY_TYPE or isinstance(arg1, type1)) \ if ((type1 is ANY_TYPE or isinstance(arg1, type1)) and
and (type2 is ANY_TYPE or isinstance(arg2, type2)): (type2 is ANY_TYPE or isinstance(arg2, type2))):
pass pass
elif (type1 is ANY_TYPE or isinstance(arg2, type1)) \ elif ((type1 is ANY_TYPE or isinstance(arg2, type1)) and
and (type2 is ANY_TYPE or isinstance(arg1, type2)): (type2 is ANY_TYPE or isinstance(arg1, type2))):
arg1, arg2 = arg2, arg1 arg1, arg2 = arg2, arg1
else: else:
return old_f(arg1, arg2, *rest) return old_f(arg1, arg2, *rest)
...@@ -337,8 +335,9 @@ def comm_guard(type1, type2): ...@@ -337,8 +335,9 @@ def comm_guard(type1, type2):
return type.__name__ return type.__name__
new_f.__doc__ = (str(old_f.__doc__) + "\n" + new_f.__doc__ = (str(old_f.__doc__) + "\n" +
", ".join([typename(type) for type in (type1, type2)]) + ", ".join([typename(type)
"\n" + str(f.__doc__ or "")) for type in (type1, type2)]) +
"\n" + str(f.__doc__ or ""))
return new_f return new_f
return wrap return wrap
...@@ -369,8 +368,8 @@ def type_guard(type1): ...@@ -369,8 +368,8 @@ def type_guard(type1):
return type.__name__ return type.__name__
new_f.__doc__ = (str(old_f.__doc__) + "\n" + new_f.__doc__ = (str(old_f.__doc__) + "\n" +
", ".join([typename(type) for type in (type1,)]) + ", ".join([typename(type) for type in (type1,)]) +
"\n" + str(f.__doc__ or "")) "\n" + str(f.__doc__ or ""))
return new_f return new_f
return wrap return wrap
...@@ -412,9 +411,8 @@ def give_variables_names(variables): ...@@ -412,9 +411,8 @@ def give_variables_names(variables):
var.name = (var.name or "") + "_%d" % i var.name = (var.name or "") + "_%d" % i
if not unique(map(str, variables)): if not unique(map(str, variables)):
raise ValueError("Not all variables have unique names." raise ValueError("Not all variables have unique names. Maybe you've "
"Maybe you've named some of the variables identically") "named some of the variables identically")
return variables return variables
......
...@@ -269,7 +269,6 @@ whitelist_flake8 = [ ...@@ -269,7 +269,6 @@ whitelist_flake8 = [
"sparse/sandbox/sp.py", "sparse/sandbox/sp.py",
"gof/destroyhandler.py", "gof/destroyhandler.py",
"gof/unify.py", "gof/unify.py",
"gof/utils.py",
"gof/graph.py", "gof/graph.py",
"gof/callcache.py", "gof/callcache.py",
"gof/type.py", "gof/type.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论