E203,E305,E402,E501,E721,E741,F401,F403,F405,F821,F841,F999,W503,W504,C408,
# ignores below are temporary, fix them and remove please!
B007,B008
-exclude = docs/src,venv,third_party,caffe2,scripts,docs/caffe2,tools/amd_build/pyHIPIFY,torch/lib/include,torch/lib/tmp_install,build,torch/include
+exclude = docs/src,venv,third_party,caffe2,scripts,docs/caffe2,tools/amd_build/pyHIPIFY,torch/lib/include,torch/lib/tmp_install,build,torch/include,torch/__init__.pyi
python: "3.7"
dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069)
sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069)
- install: pip install flake8-mypy flake8-bugbear
+ install:
+ - pip install flake8-mypy
+ # Apparently Facebook runs master (not released)
+ - pip install git+https://github.com/PyCQA/flake8-bugbear.git@d9444713a51a9fb6ee8cd2d88fca85e9ff0c2d58
script: flake8
- name: "MyPy typecheck"
python: "3.6"
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
# `add_stylesheet` (deprecated in 1.8).
- add_css = getattr(app, 'add_css_file', getattr(app, 'add_stylesheet'))
+ add_css = getattr(app, 'add_css_file', app.add_stylesheet)
for css_file in html_css_files:
add_css(css_file)
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
# `add_stylesheet` (deprecated in 1.8).
- add_css = getattr(app, 'add_css_file', getattr(app, 'add_stylesheet'))
+ add_css = getattr(app, 'add_css_file', app.add_stylesheet)
for css_file in html_css_files:
add_css(css_file)
class FilelikeMock(object):
def __init__(self, data, has_fileno=True, has_readinto=False):
if has_readinto:
- setattr(self, 'readinto', self.readinto_opt)
+ self.readinto = self.readinto_opt
if has_fileno:
# Python 2's StringIO.StringIO has no fileno attribute.
# This is used to test that.
- setattr(self, 'fileno', self.fileno_opt)
+ self.fileno = self.fileno_opt
self.calls = set()
self.bytesio = io.BytesIO(data)
"std", "sum", "var", "max", "min"]
def normfn_attr(t, dim, keepdim=False, out=None):
- attr = getattr(torch, "norm")
+ attr = torch.norm
return attr(t, 2, dim, keepdim, out=out)
for fn_name in dim_red_fns:
for lhs in lhsTensors:
lhs_expanded = lhs.expand(*(torch.Size(full_batch_dims) + torch.Size(lhs_mat_dims)))
- lhs_expanded_matmul_fn = getattr(lhs_expanded, "matmul")
+ lhs_expanded_matmul_fn = lhs_expanded.matmul
for rhs in rhsTensors:
rhs_expanded = ((rhs if len(rhs_dims) != 1 else rhs.unsqueeze(-1)).
expand(*(torch.Size(full_batch_dims) + torch.Size(rhs_mat_dims))))
truth = maybe_squeeze_result(lhs_expanded, rhs_expanded, lhs_expanded_matmul_fn(rhs_expanded))
for l in (lhs, lhs_expanded):
for r in (rhs, rhs_expanded):
- l_matmul_fn = getattr(l, "matmul")
+ l_matmul_fn = l.matmul
result = maybe_squeeze_result(l, r, l_matmul_fn(r))
self.assertEqual(truth, result)
# test torch.matmul function as well
return TupleInstance(types)
class TupleInstance(object):
+ __slots__ = ['__args__']
+
def __init__(self, types):
- setattr(self, '__args__', types)
+ self.__args__ = types
class ListInstance(object):
+ __slots__ = ['__args__']
+
def __init__(self, types):
- setattr(self, '__args__', types)
+ self.__args__ = types
class ListCls(object):
def __getitem__(self, types):
return TupleInstance(types)
class DictInstance(object):
+ __slots__ = ['__args__']
+
def __init__(self, types):
- setattr(self, '__args__', types)
+ self.__args__ = types
class DictCls(object):
def __getitem__(self, types):
if PY3:
import builtins
- exec_ = getattr(builtins, "exec")
+ # See https://github.com/PyCQA/flake8-bugbear/issues/64
+ exec_ = getattr(builtins, "exec") # noqa: B009
else:
def exec_(_code_, _globs_=None, _locs_=None):
"""Execute code in a namespace."""
has_static_forward = isinstance(forward, staticmethod) or isinstance(forward, classmethod)
break
- setattr(cls, '_is_legacy', not has_static_forward)
+ cls._is_legacy = not has_static_forward
# old-style functions
if not has_static_forward:
return super(FunctionMeta, cls).__init__(name, bases, attrs)
backward_fn = type(name + 'Backward', (BackwardCFunction,), {'_forward_cls': cls})
- setattr(cls, '_backward_cls', backward_fn)
+ cls._backward_cls = backward_fn
return super(FunctionMeta, cls).__init__(name, bases, attrs)