Skip to content

Commit 3815d7a

Browse files
authored
Upgrade string literals to raw string (PaddlePaddle#28989)
* upgrade comment string to raw string * fix string in * fix string with ' ' * revert update on comments * upgrade only necessary * fix sample code checker * fix comments with '''
1 parent 767d0ba commit 3815d7a

File tree

109 files changed

+586
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+586
-449
lines changed

paddle/scripts/conda_build.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
#!/bin/python
2+
3+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
217
#
318
import platform
419
from sys import argv
@@ -120,7 +135,7 @@ def __init__(self):
120135
self.py_str = ["py27", "py35", "py36", "py37"]
121136
self.pip_end = ".whl --no-deps"
122137
self.pip_prefix_linux = "pip install /package/paddlepaddle"
123-
self.pip_prefix_windows = "pip install C:\package\paddlepaddle"
138+
self.pip_prefix_windows = r"pip install C:\package\paddlepaddle"
124139
self.pip_gpu = "_gpu-"
125140
self.pip_cpu = "-"
126141
self.mac_pip = [
@@ -216,15 +231,15 @@ def meta_build_windows(var,
216231
- matplotlib"""
217232
if not (cuda_str == None):
218233
meta_str = meta_str + cuda_str
219-
234+
220235
blt_str = var.blt_const + blt_var
221236
if (python_str == var.python27):
222237
blt_str = blt_str + """
223238
pip install C:\package\opencv_python-4.2.0.32-cp27-cp27m-win_amd64.whl"""
224239
else:
225240
meta_str = meta_str + """
226241
- opencv>=3.4.2"""
227-
242+
228243
meta_str = meta_str + var.test + var.about
229244
meta_filename = "meta.yaml"
230245
build_filename = "bld.bat"

python/paddle/dataset/imdb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def train(word_idx):
116116
:rtype: callable
117117
"""
118118
return reader_creator(
119-
re.compile("aclImdb/train/pos/.*\.txt$"),
120-
re.compile("aclImdb/train/neg/.*\.txt$"), word_idx)
119+
re.compile(r"aclImdb/train/pos/.*\.txt$"),
120+
re.compile(r"aclImdb/train/neg/.*\.txt$"), word_idx)
121121

122122

123123
@deprecated(
@@ -137,8 +137,8 @@ def test(word_idx):
137137
:rtype: callable
138138
"""
139139
return reader_creator(
140-
re.compile("aclImdb/test/pos/.*\.txt$"),
141-
re.compile("aclImdb/test/neg/.*\.txt$"), word_idx)
140+
re.compile(r"aclImdb/test/pos/.*\.txt$"),
141+
re.compile(r"aclImdb/test/neg/.*\.txt$"), word_idx)
142142

143143

144144
@deprecated(
@@ -153,7 +153,7 @@ def word_dict():
153153
:rtype: dict
154154
"""
155155
return build_dict(
156-
re.compile("aclImdb/((train)|(test))/((pos)|(neg))/.*\.txt$"), 150)
156+
re.compile(r"aclImdb/((train)|(test))/((pos)|(neg))/.*\.txt$"), 150)
157157

158158

159159
@deprecated(

python/paddle/dataset/tests/imdb_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import unittest
1919
import re
2020

21-
TRAIN_POS_PATTERN = re.compile("aclImdb/train/pos/.*\.txt$")
22-
TRAIN_NEG_PATTERN = re.compile("aclImdb/train/neg/.*\.txt$")
23-
TRAIN_PATTERN = re.compile("aclImdb/train/.*\.txt$")
21+
TRAIN_POS_PATTERN = re.compile(r"aclImdb/train/pos/.*\.txt$")
22+
TRAIN_NEG_PATTERN = re.compile(r"aclImdb/train/neg/.*\.txt$")
23+
TRAIN_PATTERN = re.compile(r"aclImdb/train/.*\.txt$")
2424

25-
TEST_POS_PATTERN = re.compile("aclImdb/test/pos/.*\.txt$")
26-
TEST_NEG_PATTERN = re.compile("aclImdb/test/neg/.*\.txt$")
27-
TEST_PATTERN = re.compile("aclImdb/test/.*\.txt$")
25+
TEST_POS_PATTERN = re.compile(r"aclImdb/test/pos/.*\.txt$")
26+
TEST_NEG_PATTERN = re.compile(r"aclImdb/test/neg/.*\.txt$")
27+
TEST_PATTERN = re.compile(r"aclImdb/test/.*\.txt$")
2828

2929

3030
class TestIMDB(unittest.TestCase):

python/paddle/distributed/fleet/base/distributed_strategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def dgc(self, flag):
862862

863863
@property
864864
def dgc_configs(self):
865-
"""
865+
r"""
866866
Set Deep Gradient Compression training configurations. In general, dgc has serveral configurable
867867
settings that can be configured through a dict.
868868

python/paddle/distributed/fleet/launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""
14+
r"""
1515
fleetrun is a module that spawns multiple distributed
1616
process on each training node for gpu training and cpu training.
1717
Usage:

python/paddle/distributed/fleet/meta_optimizers/parameter_server_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ def get_sys_free_mem():
158158
['vm_stat'], stdout=subprocess.PIPE).communicate()[0]
159159
# Process vm_stat
160160
vmLines = vm.split('\n')
161-
sep = re.compile(':[\s]+')
161+
sep = re.compile(r':[\s]+')
162162
vmStats = {}
163163
for row in range(1, len(vmLines) - 2):
164164
rowText = vmLines[row].strip()
165165
rowElements = sep.split(rowText)
166166
vmStats[(rowElements[0]
167-
)] = int(rowElements[1].strip('\.')) * 4096
167+
)] = int(rowElements[1].strip(r'\.')) * 4096
168168
return vmStats["Pages free"]
169169
elif platform.system() == "Linux":
170170
mems = {}

python/paddle/distributed/launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""
14+
r"""
1515
paddle.distributed.launch is a module that spawns multiple distributed
1616
process on each training node for gpu training.
1717
Usage:

python/paddle/distribution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _check_values_dtype_in_probs(self, param, value):
166166

167167

168168
class Uniform(Distribution):
169-
"""Uniform distribution with `low` and `high` parameters.
169+
r"""Uniform distribution with `low` and `high` parameters.
170170
171171
Mathematical Details
172172
@@ -374,7 +374,7 @@ def probs(self, value):
374374
return elementwise_div((lb * ub), (self.high - self.low), name=name)
375375

376376
def entropy(self):
377-
"""Shannon entropy in nats.
377+
r"""Shannon entropy in nats.
378378
379379
The entropy is
380380
@@ -391,7 +391,7 @@ def entropy(self):
391391

392392

393393
class Normal(Distribution):
394-
"""The Normal distribution with location `loc` and `scale` parameters.
394+
r"""The Normal distribution with location `loc` and `scale` parameters.
395395
396396
Mathematical details
397397
@@ -534,7 +534,7 @@ def sample(self, shape, seed=0):
534534
return output
535535

536536
def entropy(self):
537-
"""Shannon entropy in nats.
537+
r"""Shannon entropy in nats.
538538
539539
The entropy is
540540
@@ -599,7 +599,7 @@ def probs(self, value):
599599
name=name)
600600

601601
def kl_divergence(self, other):
602-
"""The KL-divergence between two normal distributions.
602+
r"""The KL-divergence between two normal distributions.
603603
604604
The probability density function (pdf) is
605605
@@ -644,7 +644,7 @@ def kl_divergence(self, other):
644644

645645

646646
class Categorical(Distribution):
647-
"""
647+
r"""
648648
Categorical distribution is a discrete probability distribution that
649649
describes the possible results of a random variable that can take on
650650
one of K possible categories, with the probability of each category

python/paddle/fluid/clip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _append_clip_op(self, block, grad_name):
4040

4141

4242
class ErrorClipByValue(BaseErrorClipAttr):
43-
"""
43+
r"""
4444
Clips tensor values to the range [min, max].
4545
4646
Given a tensor ``t`` (see Examples below), this operation clips its value \
@@ -241,7 +241,7 @@ def _create_operators(self, param, grad):
241241

242242

243243
class ClipGradByNorm(ClipGradBase):
244-
"""
244+
r"""
245245
Limit the l2 norm of multi-dimensional Tensor :math:`X` to ``clip_norm`` .
246246
247247
- If the l2 norm of :math:`X` is greater than ``clip_norm`` , :math:`X` will be compressed by a ratio.
@@ -343,7 +343,7 @@ def _create_operators(self, param, grad):
343343

344344

345345
class ClipGradByGlobalNorm(ClipGradBase):
346-
"""
346+
r"""
347347
Given a list of Tensor :math:`t\_list` , calculate the global norm for the elements of all tensors in
348348
:math:`t\_list` , and limit it to ``clip_norm`` .
349349

python/paddle/fluid/contrib/layers/nn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def var_conv_2d(input,
137137
act=None,
138138
dtype='float32',
139139
name=None):
140-
"""
140+
r"""
141141
The var_conv_2d layer calculates the output base on the :attr:`input` with variable length,
142142
row, col, input channel, filter size and strides. Both :attr:`input`, :attr:`row`,
143143
and :attr:`col` are 1-level LodTensor. The convolution operation is same as conv2d layer with
@@ -477,7 +477,7 @@ def fused_embedding_seq_pool(input,
477477
combiner='sum',
478478
param_attr=None,
479479
dtype='float32'):
480-
"""
480+
r"""
481481
**Embedding Sequence pool**
482482
483483
This layer is the fusion of lookup table and sequence_pool.
@@ -1442,7 +1442,7 @@ def batch_fc(input, param_size, param_attr, bias_size, bias_attr, act=None):
14421442

14431443

14441444
def _pull_box_extended_sparse(input, size, extend_size=64, dtype='float32'):
1445-
"""
1445+
r"""
14461446
**Pull Box Extended Sparse Layer**
14471447
This layer is used to lookup embeddings of IDs, provided by :attr:`input`, in
14481448
BoxPS lookup table. The result of this lookup is the embedding of each ID in the
@@ -1640,7 +1640,7 @@ def fused_bn_add_act(x,
16401640
moving_variance_name=None,
16411641
act=None,
16421642
name=None):
1643-
"""
1643+
r"""
16441644
This Op performs batch norm on input x, and adds the result to input y. Then
16451645
it performs activation on the sum. The data format of inputs must be NHWC
16461646
`[batch, in_height, in_width, in_channels]`.

python/paddle/fluid/contrib/layers/rnn_impl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def basic_gru(input,
175175
activation=None,
176176
dtype='float32',
177177
name='basic_gru'):
178-
"""
178+
r"""
179179
GRU implementation using basic operator, supports multiple layers and bidirectional gru.
180180
181181
.. math::
@@ -418,7 +418,7 @@ def basic_lstm(input,
418418
forget_bias=1.0,
419419
dtype='float32',
420420
name='basic_lstm'):
421-
"""
421+
r"""
422422
LSTM implementation using basic operators, supports multiple layers and bidirectional LSTM.
423423
424424
.. math::
@@ -697,7 +697,7 @@ def get_single_direction_output(rnn_input,
697697

698698

699699
class BasicLSTMUnit(Layer):
700-
"""
700+
r"""
701701
****
702702
BasicLSTMUnit class, Using basic operator to build LSTM
703703
The algorithm can be described as the code below.

python/paddle/fluid/contrib/memory_usage_calc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545

4646
def memory_usage(program, batch_size):
47-
"""
47+
r"""
4848
Get the estimate memory usage of program with input batch size.
4949
5050
Args:

python/paddle/fluid/contrib/slim/quantization/imperative/qat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self,
6464
act_preprocess_layer=None,
6565
weight_quantize_layer=None,
6666
act_quantize_layer=None):
67-
"""
67+
r"""
6868
The constructor for ImperativeQuantAware.
6969
7070
Args:

python/paddle/fluid/contrib/slim/quantization/imperative/quant_nn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
class FakeQuantMovingAverage(layers.Layer):
33-
"""
33+
r"""
3434
FakeQuantMovingAverage layer does the moving_average_abs_max quant and then dequant.
3535
Its computational formula is described as below:
3636
@@ -128,7 +128,7 @@ def forward(self, input):
128128

129129

130130
class FakeQuantAbsMax(layers.Layer):
131-
"""
131+
r"""
132132
FakeQuantAbsMax layer does the abs_max quant and then dequant.
133133
Its computational formula is described as below:
134134
@@ -545,7 +545,7 @@ def forward(self, input):
545545

546546
class MovingAverageAbsMaxScale(layers.Layer):
547547
def __init__(self, name=None, moving_rate=0.9, dtype='float32'):
548-
"""
548+
r"""
549549
MovingAverageMaxScale layer is used to calculating the output quantization scale of Layer.
550550
Its computational formula is described as below:
551551

python/paddle/fluid/contrib/slim/quantization/quant_int8_mkldnn_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QuantInt8MkldnnPass(object):
3737
"""
3838

3939
def __init__(self, _scope=None, _place=None):
40-
"""
40+
r"""
4141
Args:
4242
scope(fluid.Scope): scope is used to initialize the new parameters.
4343
place(fluid.CPUPlace): place is used to initialize the new parameters.

python/paddle/fluid/contrib/slim/quantization/quantization_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def __init__(self,
239239
act_preprocess_func=None,
240240
optimizer_func=None,
241241
executor=None):
242-
"""
242+
r"""
243243
Constructor.
244244
245245
Args:

python/paddle/fluid/contrib/utils/hdfs_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
class HDFSClient(object):
36-
"""
36+
r"""
3737
A tool of HDFS
3838
3939
Args:
@@ -376,7 +376,7 @@ def ls(self, hdfs_path):
376376
_logger.info("HDFS list path: {} successfully".format(hdfs_path))
377377

378378
ret_lines = []
379-
regex = re.compile('\s+')
379+
regex = re.compile(r'\s+')
380380
out_lines = output.strip().split("\n")
381381
for line in out_lines:
382382
re_line = regex.split(line)
@@ -418,7 +418,7 @@ def sort_by_time(v1, v2):
418418
_logger.info("HDFS list all files: {} successfully".format(
419419
hdfs_path))
420420
lines = []
421-
regex = re.compile('\s+')
421+
regex = re.compile(r'\s+')
422422
out_lines = output.strip().split("\n")
423423
for line in out_lines:
424424
re_line = regex.split(line)

python/paddle/fluid/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def less_than_ver(a, b):
224224
import operator
225225

226226
def to_list(s):
227-
s = re.sub('(\.0+)+$', '', s)
227+
s = re.sub(r'(\.0+)+$', '', s)
228228
return [int(x) for x in s.split('.')]
229229

230230
return operator.lt(to_list(a), to_list(b))

0 commit comments

Comments
 (0)