Skip to content

Commit 2a7dab4

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 f14d19d commit 2a7dab4

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
@@ -282,7 +282,7 @@ def save_memoryview(self, obj):
282282
def save_buffer(self, obj):
283283
self.save(str(obj))
284284

285-
dispatch[buffer] = save_buffer
285+
dispatch[buffer] = save_buffer # noqa: F821 'buffer' was removed in Python 3
286286

287287
def save_module(self, obj):
288288
"""
@@ -815,10 +815,10 @@ def save_ellipsis(self, obj):
815815
def save_not_implemented(self, obj):
816816
self.save_reduce(_gen_not_implemented, ())
817817

818-
if PY3:
819-
dispatch[io.TextIOWrapper] = save_file
820-
else:
818+
try: # Python 2
821819
dispatch[file] = save_file
820+
except NameError: # Python 3
821+
dispatch[io.TextIOWrapper] = save_file
822822

823823
dispatch[type(Ellipsis)] = save_ellipsis
824824
dispatch[type(NotImplemented)] = save_not_implemented

0 commit comments

Comments
 (0)