Skip to content

Commit 59d2c20

Browse files
authored
Fix off by one in pickle protocol tests (#618)
I've noticed several tests which I assume are meant to test all pickle protocols but are missing the `+ 1` needed to test the highest protocol in a range. This adds the highest protocol to these tests.
1 parent 40e22eb commit 59d2c20

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/test_typing_extensions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def test_cannot_instantiate(self):
525525
type(self.bottom_type)()
526526

527527
def test_pickle(self):
528-
for proto in range(pickle.HIGHEST_PROTOCOL):
528+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
529529
pickled = pickle.dumps(self.bottom_type, protocol=proto)
530530
self.assertIs(self.bottom_type, pickle.loads(pickled))
531531

@@ -5904,7 +5904,7 @@ def test_pickle(self):
59045904
P_co = ParamSpec('P_co', covariant=True)
59055905
P_contra = ParamSpec('P_contra', contravariant=True)
59065906
P_default = ParamSpec('P_default', default=[int])
5907-
for proto in range(pickle.HIGHEST_PROTOCOL):
5907+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
59085908
with self.subTest(f'Pickle protocol {proto}'):
59095909
for paramspec in (P, P_co, P_contra, P_default):
59105910
z = pickle.loads(pickle.dumps(paramspec, proto))
@@ -6327,7 +6327,7 @@ def test_typevar(self):
63276327
self.assertIs(StrT.__bound__, LiteralString)
63286328

63296329
def test_pickle(self):
6330-
for proto in range(pickle.HIGHEST_PROTOCOL):
6330+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
63316331
pickled = pickle.dumps(LiteralString, protocol=proto)
63326332
self.assertIs(LiteralString, pickle.loads(pickled))
63336333

@@ -6374,7 +6374,7 @@ def return_tuple(self) -> TupleSelf:
63746374
return (self, self)
63756375

63766376
def test_pickle(self):
6377-
for proto in range(pickle.HIGHEST_PROTOCOL):
6377+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
63786378
pickled = pickle.dumps(Self, protocol=proto)
63796379
self.assertIs(Self, pickle.loads(pickled))
63806380

@@ -6586,7 +6586,7 @@ def test_pickle(self):
65866586
Ts = TypeVarTuple('Ts')
65876587
Ts_default = TypeVarTuple('Ts_default', default=Unpack[Tuple[int, str]])
65886588

6589-
for proto in range(pickle.HIGHEST_PROTOCOL):
6589+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
65906590
for typevartuple in (Ts, Ts_default):
65916591
z = pickle.loads(pickle.dumps(typevartuple, proto))
65926592
self.assertEqual(z.__name__, typevartuple.__name__)
@@ -7597,7 +7597,7 @@ def test_pickle(self):
75977597
U_co = typing_extensions.TypeVar('U_co', covariant=True)
75987598
U_contra = typing_extensions.TypeVar('U_contra', contravariant=True)
75997599
U_default = typing_extensions.TypeVar('U_default', default=int)
7600-
for proto in range(pickle.HIGHEST_PROTOCOL):
7600+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
76017601
for typevar in (U, U_co, U_contra, U_default):
76027602
z = pickle.loads(pickle.dumps(typevar, proto))
76037603
self.assertEqual(z.__name__, typevar.__name__)
@@ -7746,7 +7746,7 @@ def test_pickle(self):
77467746
global U, U_infer # pickle wants to reference the class by name
77477747
U = typing_extensions.TypeVar('U')
77487748
U_infer = typing_extensions.TypeVar('U_infer', infer_variance=True)
7749-
for proto in range(pickle.HIGHEST_PROTOCOL):
7749+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
77507750
for typevar in (U, U_infer):
77517751
z = pickle.loads(pickle.dumps(typevar, proto))
77527752
self.assertEqual(z.__name__, typevar.__name__)
@@ -8351,7 +8351,7 @@ def test_equality(self):
83518351

83528352
def test_pickle(self):
83538353
doc_info = Doc("Who to say hi to")
8354-
for proto in range(pickle.HIGHEST_PROTOCOL):
8354+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
83558355
pickled = pickle.dumps(doc_info, protocol=proto)
83568356
self.assertEqual(doc_info, pickle.loads(pickled))
83578357

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy