Fix for Python 3.10: use sys.version_info instead of comparing sys.version to string

This commit is contained in:
Hugo 2020-01-11 17:47:04 +02:00
parent 459c5cb980
commit dc4278b527
2 changed files with 5 additions and 5 deletions

View File

@ -31,7 +31,7 @@ from tensorflow.python.saved_model import loader_impl
from tensorflow.python.util.tf_export import keras_export
# pylint: disable=g-import-not-at-top
if sys.version >= '3.4':
if sys.version_info >= (3, 4):
import pathlib
try:
import h5py
@ -98,7 +98,7 @@ def save_model(model,
default_format = 'tf' if tf2.enabled() else 'h5'
save_format = save_format or default_format
if sys.version >= '3.4' and isinstance(filepath, pathlib.Path):
if sys.version_info >= (3, 4) and isinstance(filepath, pathlib.Path):
filepath = str(filepath)
if (save_format == 'h5' or
@ -151,7 +151,7 @@ def load_model(filepath, custom_objects=None, compile=True): # pylint: disable=
isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
if sys.version >= '3.4' and isinstance(filepath, pathlib.Path):
if sys.version_info >= (3, 4) and isinstance(filepath, pathlib.Path):
filepath = str(filepath)
if isinstance(filepath, six.string_types):
loader_impl.parse_saved_model(filepath)

View File

@ -35,7 +35,7 @@ from tensorflow.python.ops import lookup_ops
from tensorflow.python.platform import test
from tensorflow.python.saved_model import loader_impl
if sys.version >= '3.4':
if sys.version_info >= (3, 4):
import pathlib # pylint:disable=g-import-not-at-top
try:
import h5py # pylint:disable=g-import-not-at-top
@ -94,7 +94,7 @@ class TestSaveModel(test.TestCase):
@test_util.run_v2_only
def test_save_load_tf_pathlib(self):
if sys.version >= '3.4':
if sys.version_info >= (3, 4):
path = pathlib.Path(self.get_temp_dir()) / 'model'
save.save_model(self.model, path, save_format='tf')
save.load_model(path)