Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jsonpointer-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Iterable, Iterator
from re import Pattern
from typing import Any, Final, TypeVar

from typing_extensions import Self
from typing_extensions import Self, deprecated

_T = TypeVar("_T")

Expand All @@ -21,6 +21,7 @@ def set_pointer(
create: bool = False,
) -> Any: ...
def resolve_pointer(doc: Any, pointer: str, default: Any = ...) -> Any: ...
@deprecated("Use itertools.pairwise() instead")
def pairwise(iterable: Iterable[_T]) -> Iterator[tuple[_T, _T]]: ...

class JsonPointerException(Exception): ...
Expand Down
22 changes: 9 additions & 13 deletions jsonpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
__license__ = 'Modified BSD License'

import copy
import itertools
import re
import warnings
from collections.abc import Mapping, Sequence
from itertools import tee, chain
from itertools import chain

_nothing = object()

Expand Down Expand Up @@ -128,19 +130,13 @@ def pairwise(iterable):

s -> (s0,s1), (s1,s2), (s2, s3), ...

>>> list(pairwise([]))
[]

>>> list(pairwise([1]))
[]

>>> list(pairwise([1, 2, 3, 4]))
[(1, 2), (2, 3), (3, 4)]
.. deprecated:: 3.12
Use :func:`itertools.pairwise` instead.
"""
a, b = tee(iterable)
for _ in b:
break
return zip(a, b)
warnings.warn('jsonpointer.pairwise() is deprecated, '
'use itertools.pairwise() instead',
DeprecationWarning, stacklevel=2)
return itertools.pairwise(iterable)


class JsonPointerException(Exception):
Expand Down
11 changes: 11 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ def test_string_not_indexable(self):

@unittest.skipUnless(hasattr(sys, 'get_int_max_str_digits'),
'Integer string conversion limits are not available')
class PairwiseTests(unittest.TestCase):

def test_pairwise_is_deprecated(self):
for items, expected in (([], []), ([1], []),
([1, 2, 3, 4], [(1, 2), (2, 3), (3, 4)])):
with self.subTest(items=items):
with self.assertWarns(DeprecationWarning):
result = jsonpointer.pairwise(items)
self.assertEqual(list(result), expected)


class LargeIndexTests(unittest.TestCase):

def setUp(self):
Expand Down