Fix lstrip bug revealed by B005 lint (#18177)
authorEdward Yang <ezyang@fb.com>
Thu, 21 Mar 2019 14:50:45 +0000 (07:50 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 21 Mar 2019 14:56:24 +0000 (07:56 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18177
ghimport-source-id: fbbf915b66762fc88bc5b541464e71ba27500958

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**

lstrip() doesn't strip a prefix; it strips all of the characters
in the passed in string.  B005 lint revealed this.  Replaced with
substring operation.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Differential Revision: D14530873

fbshipit-source-id: 13b3438fcc3cce13b5110730dc3d0b528a52930f

.flake8
aten/src/ATen/common_with_cwrap.py
torch/_thnn/utils.py

diff --git a/.flake8 b/.flake8
index 7f7c24a..3fa97a3 100644 (file)
--- 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!
-    B005,B006,B007,B008,B902,B903
+    B006,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
index 977638a..24eb2a1 100644 (file)
@@ -187,14 +187,14 @@ def parse_header(path):
     generic_functions = []
     for l, c in lines:
         if l.startswith('TH_API void THNN_'):
-            fn_name = l.lstrip('TH_API void THNN_')
+            fn_name = l[len('TH_API void THNN_'):]
             if fn_name[0] == '(' and fn_name[-2] == ')':
                 fn_name = fn_name[1:-2]
             else:
                 fn_name = fn_name[:-1]
             generic_functions.append(Function(fn_name))
         elif l.startswith('THC_API void THNN_'):
-            fn_name = l.lstrip('THC_API void THNN_')
+            fn_name = l[len('THC_API void THNN_'):]
             if fn_name[0] == '(' and fn_name[-2] == ')':
                 fn_name = fn_name[1:-2]
             else:
index 7420275..2c73b3c 100644 (file)
@@ -95,14 +95,14 @@ def parse_header(path):
     generic_functions = []
     for l, c in lines:
         if l.startswith('TH_API void THNN_'):
-            fn_name = l.lstrip('TH_API void THNN_')
+            fn_name = l[len('TH_API void THNN_'):]
             if fn_name[0] == '(' and fn_name[-2] == ')':
                 fn_name = fn_name[1:-2]
             else:
                 fn_name = fn_name[:-1]
             generic_functions.append(Function(fn_name))
         elif l.startswith('THC_API void THNN_'):
-            fn_name = l.lstrip('THC_API void THNN_')
+            fn_name = l[len('THC_API void THNN_'):]
             if fn_name[0] == '(' and fn_name[-2] == ')':
                 fn_name = fn_name[1:-2]
             else: