mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #10180: Pickling file objects is now explicitly forbidden, since
unpickling them produced nonsensical results.
This commit is contained in:
parent
4a5f9677f3
commit
243757eb79
6 changed files with 57 additions and 0 deletions
|
@ -30,6 +30,7 @@ import abc
|
|||
import signal
|
||||
import errno
|
||||
import warnings
|
||||
import pickle
|
||||
from itertools import cycle, count
|
||||
from collections import deque
|
||||
from test import support
|
||||
|
@ -2566,6 +2567,23 @@ class MiscIOTest(unittest.TestCase):
|
|||
self._check_warn_on_dealloc_fd("r")
|
||||
|
||||
|
||||
def test_pickling(self):
|
||||
# Pickling file objects is forbidden
|
||||
for kwargs in [
|
||||
{"mode": "w"},
|
||||
{"mode": "wb"},
|
||||
{"mode": "wb", "buffering": 0},
|
||||
{"mode": "r"},
|
||||
{"mode": "rb"},
|
||||
{"mode": "rb", "buffering": 0},
|
||||
{"mode": "w+"},
|
||||
{"mode": "w+b"},
|
||||
{"mode": "w+b", "buffering": 0},
|
||||
]:
|
||||
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
with self.open(support.TESTFN, **kwargs) as f:
|
||||
self.assertRaises(TypeError, pickle.dumps, f, protocol)
|
||||
|
||||
class CMiscIOTest(MiscIOTest):
|
||||
io = io
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue