Skip to content

Commit c70062e

Browse files
authored
Use Python 3.8 features and cleanup 3.7 branches (PaddlePaddle#59871)
* Use Python 3.8 features and cleanup 3.7 branches * fix version compare
1 parent efad2b1 commit c70062e

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed

paddle/fluid/pir/dialect/op_generator/api_gen.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,11 @@ def _gen_check_data_type(self, op_info, op_name):
594594
for name in op_info.input_name_list[::-1]:
595595
type = mapping_input_name_to_type[name]
596596
optional = mapping_input_name_to_optional[name]
597-
function_name = mapping_type_to_function_name.get(type, None)
598-
if function_name is None:
597+
if (
598+
function_name := mapping_type_to_function_name.get(
599+
type, None
600+
)
601+
) is None:
599602
continue
600603

601604
if optional == 'false':
@@ -635,8 +638,9 @@ def _gen_check_data_type(self, op_info, op_name):
635638
if name not in mapping_name_to_type:
636639
return ""
637640
type = mapping_name_to_type[name]
638-
function_name = mapping_type_to_function_name.get(type, None)
639-
if function_name is None:
641+
if (
642+
function_name := mapping_type_to_function_name.get(type, None)
643+
) is None:
640644
return ""
641645
return CHECK_DATA_TYPE_TEMPLATE.format(
642646
function=function_name,

python/paddle/base/core.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
# Note: from python3.8, PATH will not take effect
4242
# https://github.com/python/cpython/pull/12302
4343
# Use add_dll_directory to specify dll resolution path
44-
if sys.version_info[:2] >= (3, 8):
45-
os.add_dll_directory(third_lib_path)
44+
os.add_dll_directory(third_lib_path)
4645

4746
except ImportError as e:
4847
if os.name == 'nt':

python/paddle/base/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def _can_use_interpreter_core(program, place):
770770
return True
771771

772772

773-
@lru_cache()
773+
@lru_cache
774774
def _warning_once(msg):
775775
logging.warning(msg)
776776

python/paddle/jit/dy2static/pir_partial_program.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import itertools
16+
from functools import cached_property
1617

1718
import numpy as np
1819

@@ -33,20 +34,6 @@
3334
__all__ = []
3435

3536

36-
class cached_property:
37-
"""
38-
Descriptor to implement lazy initialization of property.
39-
"""
40-
41-
def __init__(self, function):
42-
self.function = function
43-
44-
def __get__(self, instance, cls):
45-
val = self.function(instance)
46-
setattr(instance, self.function.__name__, val)
47-
return val
48-
49-
5037
class NestSequence:
5138
"""
5239
A wrapper class that easily to flatten and restore the nest structure of

test/legacy_test/test_gast_with_compatibility.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def foo(x_new, y_new):
153153
#
154154
# More information please refer to:
155155
# https://github.com/serge-sans-paille/gast/issues/49
156-
if sys.version_info < (3, 8):
156+
if sys.version_info >= (3, 9):
157157

158158
def test_with(self):
159159
"""

0 commit comments

Comments
 (0)