From 9bc8badbcb4414a2f10995980f7158245446ae3c Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Thu, 21 Mar 2019 07:50:45 -0700 Subject: [PATCH] Fix lstrip bug revealed by B005 lint (#18177) 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 Differential Revision: D14530873 fbshipit-source-id: 13b3438fcc3cce13b5110730dc3d0b528a52930f --- .flake8 | 2 +- aten/src/ATen/common_with_cwrap.py | 4 ++-- torch/_thnn/utils.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.flake8 b/.flake8 index 7f7c24a..3fa97a3 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! - 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 diff --git a/aten/src/ATen/common_with_cwrap.py b/aten/src/ATen/common_with_cwrap.py index 977638a..24eb2a1 100644 --- a/aten/src/ATen/common_with_cwrap.py +++ b/aten/src/ATen/common_with_cwrap.py @@ -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: diff --git a/torch/_thnn/utils.py b/torch/_thnn/utils.py index 7420275..2c73b3c 100644 --- a/torch/_thnn/utils.py +++ b/torch/_thnn/utils.py @@ -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: -- 2.7.4