From 0654c7d4a7833932b51d6daa532117247347a731 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Thu, 21 Mar 2019 09:06:30 -0700 Subject: [PATCH] Fix B006 lint errors: using mutable structure in default argument. (#18178) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/18178 ghimport-source-id: 667ee76b418f505fa64b863e52a603c508dcd1bf Stack from [ghstack](https://github.com/ezyang/ghstack): * #18184 Fix B903 lint: save memory for data classes with slots/namedtuple * #18181 Fix B902 lint error: invalid first argument. * **#18178 Fix B006 lint errors: using mutable structure in default argument.** * #18177 Fix lstrip bug revealed by B005 lint Signed-off-by: Edward Z. Yang Differential Revision: D14530874 fbshipit-source-id: 38f4456a085bfe55f2a96fff53028ebd0d621604 --- .flake8 | 2 +- aten/src/ATen/code_template.py | 5 ++++- aten/src/ATen/common_with_cwrap.py | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.flake8 b/.flake8 index 3fa97a3..daed569 100644 --- a/.flake8 +++ b/.flake8 @@ -6,5 +6,5 @@ max-line-length = 120 ignore = E203,E305,E402,E501,E721,E741,F401,F403,F405,F821,F841,F999,W503,W504,C408, # ignores below are temporary, fix them and remove please! - B006,B007,B008,B902,B903 + B007,B008,B902,B903 exclude = docs/src,venv,third_party,caffe2,scripts,docs/caffe2,tools/amd_build/pyHIPIFY,torch/lib/include,torch/lib/tmp_install,build,torch/include diff --git a/aten/src/ATen/code_template.py b/aten/src/ATen/code_template.py index 186707c..8a5a01f 100644 --- a/aten/src/ATen/code_template.py +++ b/aten/src/ATen/code_template.py @@ -30,7 +30,10 @@ class CodeTemplate(object): self.pattern = pattern self.filename = filename - def substitute(self, env={}, **kwargs): + def substitute(self, env=None, **kwargs): + if env is None: + env = {} + def lookup(v): return kwargs[v] if v in kwargs else env[v] diff --git a/aten/src/ATen/common_with_cwrap.py b/aten/src/ATen/common_with_cwrap.py index 24eb2a1..5270d4a 100644 --- a/aten/src/ATen/common_with_cwrap.py +++ b/aten/src/ATen/common_with_cwrap.py @@ -95,7 +95,10 @@ def filter_unique_options(options, allow_kwarg, type_to_signature, remove_self): def enumerate_options_due_to_default(declaration, - allow_kwarg=True, type_to_signature=[], remove_self=True): + allow_kwarg=True, type_to_signature=None, remove_self=True): + + if type_to_signature is None: + type_to_signature = [] # Checks to see if an argument with a default keyword is a Tensor that # by default can be NULL. In this case, instead of generating another -- 2.7.4