Skip to content

Commit 829d6b4

Browse files
cclaussrgbkrk
authored andcommitted
'buffer' and 'file' are undefined names in Python 3
__cloudpickle.py__ refers to: * __buffer__ which was removed from Python 3 in favor of [memoryview](https://docs.python.org/2/c-api/buffer.html) * __file__ which was removed from Python 3 in favor of __io.TextIOWrapper__ The try/except approach for __file__ follows the Python porting best practice [use feature detection instead of version detection](https://docs.python.org/3/howto/pyporting.html#use-feature-detection-instead-of-version-detection).
1 parent 9badcb7 commit 829d6b4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cloudpickle/cloudpickle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def save_memoryview(self, obj):
272272
if not PY3:
273273
def save_buffer(self, obj):
274274
self.save(str(obj))
275-
dispatch[buffer] = save_buffer
275+
dispatch[buffer] = save_buffer # noqa: F821 'buffer' was removed in Python 3
276276

277277
def save_unsupported(self, obj):
278278
raise pickle.PicklingError("Cannot pickle objects of type %s" % type(obj))
@@ -801,10 +801,10 @@ def save_ellipsis(self, obj):
801801
def save_not_implemented(self, obj):
802802
self.save_reduce(_gen_not_implemented, ())
803803

804-
if PY3:
805-
dispatch[io.TextIOWrapper] = save_file
806-
else:
804+
try: # Python 2
807805
dispatch[file] = save_file
806+
except NameError: # Python 3
807+
dispatch[io.TextIOWrapper] = save_file
808808

809809
dispatch[type(Ellipsis)] = save_ellipsis
810810
dispatch[type(NotImplemented)] = save_not_implemented

0 commit comments

Comments
 (0)