Skip to content

Commit

Permalink
Rename EntryError.url to EntryError.feed_url.
Browse files Browse the repository at this point in the history
For #183.
  • Loading branch information
lemon24 committed Jun 3, 2021
1 parent ca77ffe commit 4aacc47
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
17 changes: 16 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,24 @@ Unreleased
Use :exc:`FeedMetadataNotFoundError` instead.

**This is a minor compatibility break**,
and affects only third-party code that instantiates
but only affects third-party code that instantiates
these exceptions *directly*.

* Rename the ``url`` argument of :exc:`EntryError` to ``feed_url``.
Rename :attr:`EntryError.url` to :attr:`~EntryError.feed_url`;
for backwards compatibility,
the old attribute will be available as a property **until version 2.0**,
when it **will be removed.** (:issue:`183`).

.. warning::

The signature of :exc:`EntryError` (and its subclasses)
changed from ``EntryError(url, id)`` to ``EntryError(feed_url, id)``.

**This is a minor compatibility break**,
but only affects third-party code that instantiates
these exceptions *directly* with ``url`` as a *keyword argument*.

* Rename :meth:`~Reader.remove_feed` to :meth:`~Reader.delete_feed`.
For backwards compatibility,
the old method will continue to work **until version 2.0**,
Expand Down
36 changes: 27 additions & 9 deletions src/reader/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any
from typing import Tuple

Expand Down Expand Up @@ -100,22 +101,24 @@ class ParseError(FeedError):


class EntryError(ReaderError):
"""An entry error occured."""
"""An entry error occurred.
def __init__(self, url: str, id: str, message: str = '') -> None:
super().__init__(message)
.. versionchanged:: 1.18
The ``url`` argument/attribute was renamed to ``feed_url``.
"""

# TODO: .url should be .feed_url
def __init__(self, feed_url: str, id: str, message: str = '') -> None:
super().__init__(message)

#: The feed URL.
self.url = url
self.feed_url = feed_url

#: The entry id.
self.id = id

@property
def _str(self) -> str:
return repr((self.url, self.id))
return repr((self.feed_url, self.id))

@property
def object_id(self) -> Tuple[str, str]:
Expand All @@ -124,7 +127,22 @@ def object_id(self) -> Tuple[str, str]:
.. versionadded:: 1.12
"""
return self.url, self.id
return self.feed_url, self.id

@property
def url(self) -> str:
"""Deprecated alias for :attr:`EntryError.feed_url`.
.. deprecated: 1.18
"""
warnings.warn(
"EntryError.url is deprecated "
"and will be removed in reader 2.0. "
"Use EntryError.feed_url instead.",
DeprecationWarning,
)
return self.feed_url


class EntryNotFoundError(EntryError):
Expand Down Expand Up @@ -185,8 +203,8 @@ class EntryMetadataNotFoundError(MetadataNotFoundError, EntryError):
"""

def __init__(self, url: str, id: str, key: str, message: str = '') -> None:
super().__init__(url, id, key=key, message=message)
def __init__(self, feed_url: str, id: str, key: str, message: str = '') -> None:
super().__init__(feed_url, id, key=key, message=message)


class StorageError(ReaderError):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,12 +925,12 @@ def test_mark_as_read_unread(reader, entry_arg):

with pytest.raises(EntryNotFoundError) as excinfo:
reader.mark_entry_as_read(entry_arg(entry_with_feed))
assert (excinfo.value.url, excinfo.value.id) == (entry.feed_url, entry.id)
assert (excinfo.value.feed_url, excinfo.value.id) == (entry.feed_url, entry.id)
assert 'no such entry' in excinfo.value.message

with pytest.raises(EntryNotFoundError) as excinfo:
reader.mark_entry_as_unread(entry_arg(entry_with_feed))
assert (excinfo.value.url, excinfo.value.id) == (entry.feed_url, entry.id)
assert (excinfo.value.feed_url, excinfo.value.id) == (entry.feed_url, entry.id)
assert 'no such entry' in excinfo.value.message

reader.add_feed(feed.url)
Expand Down Expand Up @@ -1648,7 +1648,7 @@ def test_get_entry(reader, entry_arg):

with pytest.raises(EntryNotFoundError) as excinfo:
reader.get_entry(entry_arg(entry.as_entry(feed=feed)))
assert (excinfo.value.url, excinfo.value.id) == (entry.feed_url, entry.id)
assert (excinfo.value.feed_url, excinfo.value.id) == (entry.feed_url, entry.id)
assert 'no such entry' in excinfo.value.message
assert reader.get_entry(entry_arg(entry.as_entry(feed=feed)), None) == None
assert reader.get_entry(entry_arg(entry.as_entry(feed=feed)), 1) == 1
Expand Down
9 changes: 9 additions & 0 deletions tests/test_reader_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pytest
from fakeparser import Parser

from reader import EntryError
from reader import EntryNotFoundError
from reader import FeedMetadataNotFoundError
from reader import FeedNotFoundError

Expand Down Expand Up @@ -69,3 +71,10 @@ def test_mark_as(reader):
with pytest.deprecated_call():
reader.mark_as_unimportant(entry)
assert not reader.get_entry(entry).important


@pytest.mark.parametrize('cls', [EntryError, EntryNotFoundError])
def test_entry_error_url(cls):
exc = cls('feed', 'id')
with pytest.deprecated_call():
assert exc.url == 'feed'

0 comments on commit 4aacc47

Please sign in to comment.