Skip to content

Commit

Permalink
Entry.feed_resolved_title: return source and feed title only if they …
Browse files Browse the repository at this point in the history
…differ.
  • Loading branch information
lemon24 committed Jan 2, 2025
1 parent 750fd93 commit de4f622
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Version 3.17

Unreleased

* Return the ``source (feed)`` form of :attr:`Entry.feed_resolved_title`
only if the source and feed titles are different.


Version 3.16
------------
Expand Down
9 changes: 8 additions & 1 deletion src/reader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,21 @@ def get_content(self, *, prefer_summary: bool = False) -> Content | None:
@property
def feed_resolved_title(self) -> str | None:
"""Feed :attr:`~Feed.resolved_title`, source :attr:`~EntrySource.title`,
or ``"{source} ({feed})"`` if both are present.
or ``"{source} ({feed})"`` if both are present and different.
.. versionadded:: 3.16
.. versionchanged:: 3.17
Return both the source and feed titles only if they are different.
"""
title = self.feed.resolved_title
source = self.source
source_title = source.title if source else None
if self.feed.title == source_title:
source_title = None
if title == source_title:
source_title = None
if not source_title:
return title
if not title:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ def entry_with_feed_title(feed=None, user=None, source=None):
entry_with_feed_title(feed='feed', user='user', source='source'),
'source (user)',
),
(entry_with_feed_title(feed='feed', source='feed'), 'feed'),
(entry_with_feed_title(feed='feed', user='user', source='user'), 'user'),
(entry_with_feed_title(feed='feed', user='user', source='feed'), 'user'),
],
)
def test_entry_feed_resolved_title(entry, title):
Expand Down

0 comments on commit de4f622

Please sign in to comment.