Skip to content

Commit 0f7187a

Browse files
Del six.PY code2 (#33607)
* del py2 code2 * fix test timeout
1 parent 79cbc8e commit 0f7187a

38 files changed

Lines changed: 337 additions & 813 deletions

python/paddle/compat.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
__all__ = []
1919

20-
if six.PY2:
21-
int_type = int
22-
long_type = long # noqa: F821
23-
else:
24-
int_type = int
25-
long_type = int
20+
int_type = int
21+
long_type = int
2622

2723

2824
# str and bytes related functions
@@ -262,7 +258,4 @@ def get_exception_message(exc):
262258
"""
263259
assert exc is not None
264260

265-
if six.PY2:
266-
return exc.message
267-
else:
268-
return str(exc)
261+
return str(exc)

python/paddle/dataset/cifar.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ def reader():
6262
if sub_name in each_item.name)
6363

6464
for name in names:
65-
if six.PY2:
66-
batch = pickle.load(f.extractfile(name))
67-
else:
68-
batch = pickle.load(
69-
f.extractfile(name), encoding='bytes')
65+
batch = pickle.load(f.extractfile(name), encoding='bytes')
7066
for item in read_batch(batch):
7167
yield item
7268

python/paddle/dataset/common.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ def download(url, module_name, md5sum, save_name=None):
101101
bar = paddle.hapi.progressbar.ProgressBar(
102102
total_iter, name='item')
103103
for data in r.iter_content(chunk_size=chunk_size):
104-
if six.PY2:
105-
data = six.b(data)
106104
f.write(data)
107105
log_index += 1
108106
bar.update(log_index, {})

python/paddle/dataset/flowers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ def reader():
132132
file = file.strip()
133133
batch = None
134134
with open(file, 'rb') as f:
135-
if six.PY2:
136-
batch = pickle.load(f)
137-
else:
138-
batch = pickle.load(f, encoding='bytes')
135+
batch = pickle.load(f, encoding='bytes')
139136

140137
if six.PY3:
141138
batch = cpt.to_text(batch)

python/paddle/distributed/fleet/utils/http_server.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
import six
1919
# NOTE: HTTPServer has a different name in python2 and python3
20-
if six.PY2:
21-
from BaseHTTPServer import HTTPServer
22-
import SimpleHTTPServer
23-
else:
24-
from http.server import HTTPServer
25-
import http.server as SimpleHTTPServer
20+
from http.server import HTTPServer
21+
import http.server as SimpleHTTPServer
2622

2723
import time
2824
import threading

python/paddle/fluid/contrib/slim/tests/quant2_int8_image_classification_comparison.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ def _predict(self,
226226
if iters == skip_batch_num:
227227
total_samples = 0
228228
infer_start_time = time.time()
229-
if six.PY2:
230-
images = map(lambda x: x[0].reshape(dshape), data)
231-
if six.PY3:
232-
images = list(map(lambda x: x[0].reshape(dshape), data))
229+
images = list(map(lambda x: x[0].reshape(dshape), data))
233230
images = np.array(images).astype('float32')
234231
labels = np.array([x[1] for x in data]).astype('int64')
235232

python/paddle/fluid/contrib/slim/tests/quant_int8_image_classification_comparison.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ def _predict(self,
196196
if iters == skip_batch_num:
197197
total_samples = 0
198198
infer_start_time = time.time()
199-
if six.PY2:
200-
images = map(lambda x: x[0].reshape(dshape), data)
201-
if six.PY3:
202-
images = list(map(lambda x: x[0].reshape(dshape), data))
199+
images = list(map(lambda x: x[0].reshape(dshape), data))
203200
images = np.array(images).astype('float32')
204201
labels = np.array([x[1] for x in data]).astype('int64')
205202

python/paddle/fluid/dataloader/dataloader_iter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
from paddle.fluid.framework import _set_expected_place, _current_expected_place
2828

2929
# NOTE: queue has a different name in python2 and python3
30-
if six.PY2:
31-
import Queue as queue
32-
else:
33-
import queue
30+
import queue
3431

3532
import paddle
3633
from .. import core, layers

python/paddle/fluid/dataloader/worker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
from .flat import _flatten_batch
2727

2828
# NOTE: queue has a different name in python2 and python3
29-
if six.PY2:
30-
import Queue as queue
31-
else:
32-
import queue
29+
import queue
3330

3431
__all__ = ['get_worker_info']
3532

python/paddle/fluid/dygraph/checkpoint.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import functools
2020
from ..framework import Variable, default_main_program, in_dygraph_mode, dygraph_only, Parameter, ParamBase, _varbase_creator, _dygraph_tracer
2121
import pickle
22-
import six
2322
from . import learning_rate_scheduler
2423
import warnings
2524
from .. import core
@@ -194,16 +193,14 @@ def load_dygraph(model_path, **configs):
194193
para_dict = {}
195194
if os.path.exists(params_file_path):
196195
with open(params_file_path, 'rb') as f:
197-
para_dict = pickle.load(f) if six.PY2 else pickle.load(
198-
f, encoding='latin1')
196+
para_dict = pickle.load(f, encoding='latin1')
199197

200198
if not config.keep_name_table and "StructuredToParameterName@@" in para_dict:
201199
del para_dict["StructuredToParameterName@@"]
202200

203201
if os.path.exists(opti_file_path):
204202
with open(opti_file_path, 'rb') as f:
205-
opti_dict = pickle.load(f) if six.PY2 else pickle.load(
206-
f, encoding='latin1')
203+
opti_dict = pickle.load(f, encoding='latin1')
207204
else:
208205
# check model path
209206
if not os.path.isdir(model_prefix):

0 commit comments

Comments
 (0)