Skip to content

Commit 9daade4

Browse files
authored
Deprecate instead of remove renamed parameters (#107)
In #94 and #102, we renamed several method parameters. This brings back the old names, but with deprecation warnings. We'll remove them fully in v0.5.0. This does *not* support parameters that were completely *removed*, though.
1 parent cbb9c14 commit 9daade4

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

docs/source/release-history.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ Breaking Changes
1010

1111
This release includes a significant overhaul of parameters for :meth:`wayback.WaybackClient.search`.
1212

13-
- The ``limit`` parameter now has a default value. There are very few cases where you should not set a ``limit`` (not doing so will typically break pagination), and there is now a default value to help prevent mistakes. We’ve also added documentation to explain how and when to adjust this value, since it is pretty complex. (:issue:`65`)
14-
1513
- Removed parameters that did nothing, could break search, or that were for internal use only: ``gzip``, ``showResumeKey``, ``resumeKey``, ``page``, ``pageSize``, ``previous_result``.
1614

1715
- Removed support for extra, arbitrary keyword parameters that could be added to each request to the search API.
1816

19-
- All parameters now use snake_case. (Previously, parameters that were passed unchanged to the HTTP API used camelCase, while others used snake_case.)
17+
- All parameters now use snake_case. (Previously, parameters that were passed unchanged to the HTTP API used camelCase, while others used snake_case.) The old, non-snake-case names are deprecated, but still work. They’ll be completely removed in v0.5.0.
2018

2119
- ``matchType`` → ``match_type``
2220
- ``fastLatest`` → ``fast_latest``
2321
- ``resolveRevisits`` → ``resolve_revisits``
2422

23+
- The ``limit`` parameter now has a default value. There are very few cases where you should not set a ``limit`` (not doing so will typically break pagination), and there is now a default value to help prevent mistakes. We’ve also added documentation to explain how and when to adjust this value, since it is pretty complex. (:issue:`65`)
24+
2525
- Expanded the method documentation to explain things in more depth and link to more external references.
2626

27-
While we were at it, we renamed the ``datetime`` parameter of :meth:`wayback.WaybackClient.get_memento` to ``timestamp`` for consistency with :class:`wayback.CdxRecord` and :class:`wayback.Memento`.
27+
While we were at it, we also renamed the ``datetime`` parameter of :meth:`wayback.WaybackClient.get_memento` to ``timestamp`` for consistency with :class:`wayback.CdxRecord` and :class:`wayback.Memento`. The old name still works for now, but it will be fully removed in v0.5.0.
2828

2929

3030
Features

wayback/_client.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from urllib3.exceptions import (ConnectTimeoutError,
3232
MaxRetryError,
3333
ReadTimeoutError)
34+
from warnings import warn
3435
from . import _utils, __version__
3536
from ._models import CdxRecord, Memento
3637
from .exceptions import (WaybackException,
@@ -369,7 +370,9 @@ def close(self):
369370
def search(self, url, *, match_type=None, limit=1000, offset=None,
370371
fast_latest=None, from_date=None, to_date=None,
371372
filter_field=None, collapse=None, resolve_revisits=True,
372-
skip_malformed_results=True):
373+
skip_malformed_results=True,
374+
# Deprecated Parameters
375+
matchType=None, fastLatest=None, resolveRevisits=None):
373376
"""
374377
Search archive.org's CDX API for all captures of a given URL. This
375378
returns an iterator of :class:`CdxRecord` objects. The `StopIteration`
@@ -510,6 +513,27 @@ def search(self, url, *, match_type=None, limit=1000, offset=None,
510513
pagination because they work differently from the `resumeKey` method
511514
this uses, and results do not include recent captures when using them.
512515
"""
516+
if matchType is not None:
517+
warn('The `matchType` parameter for search() was renamed to '
518+
'`match_type`. Support for the old name will be removed in '
519+
'wayback v0.5.0; please update your code.',
520+
DeprecationWarning,
521+
stacklevel=2)
522+
match_type = match_type or matchType
523+
if fastLatest is not None:
524+
warn('The `fastLatest` parameter for search() was renamed to '
525+
'`fast_latest`. Support for the old name will be removed in '
526+
'wayback v0.5.0; please update your code.',
527+
DeprecationWarning,
528+
stacklevel=2)
529+
fast_latest = fast_latest or fastLatest
530+
if resolveRevisits is not None:
531+
warn('The `resolveRevisits` parameter for search() was renamed to '
532+
'`resolve_revisits`. Support for the old name will be removed '
533+
'in wayback v0.5.0; please update your code.',
534+
DeprecationWarning,
535+
stacklevel=2)
536+
resolve_revisits = resolve_revisits or resolveRevisits
513537

514538
# TODO: support args that can be set multiple times: filter, collapse
515539
# Should take input as a sequence and convert to repeat query args
@@ -619,7 +643,9 @@ def search(self, url, *, match_type=None, limit=1000, offset=None,
619643

620644
def get_memento(self, url, timestamp=None, mode=Mode.original, *,
621645
exact=True, exact_redirects=None,
622-
target_window=24 * 60 * 60, follow_redirects=True):
646+
target_window=24 * 60 * 60, follow_redirects=True,
647+
# Deprecated Parameters
648+
datetime=None):
623649
"""
624650
Fetch a memento (an archived HTTP response) from the Wayback Machine.
625651
@@ -690,6 +716,14 @@ def get_memento(self, url, timestamp=None, mode=Mode.original, *,
690716
A :class:`Memento` object with information about the archived HTTP
691717
response.
692718
"""
719+
if datetime:
720+
warn('The `datetime` parameter for get_memento() was renamed to '
721+
'`timestamp`. Support for the old name will be removed '
722+
'in wayback v0.5.0; please update your code.',
723+
DeprecationWarning,
724+
stacklevel=2)
725+
timestamp = timestamp or datetime
726+
693727
if exact_redirects is None:
694728
exact_redirects = exact
695729

0 commit comments

Comments
 (0)