From 856087258b3466f09d557a054e4b7cc4cdc25638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 6 Jul 2026 05:07:41 +0100 Subject: [PATCH] dbcore: rename Database._fetch to Database.get_results This removes ambiguity with Library._fetch --- beets/dbcore/db.py | 4 ++-- beets/library/library.py | 2 +- test/dbcore/test_db.py | 25 ++++++++++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index aaaf3055e..e66f4548b 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -1384,7 +1384,7 @@ class Database: # Querying. - def _fetch( + def _get_results( self, model_cls: type[AnyModel], query: Query | None = None, @@ -1444,7 +1444,7 @@ class Database: def _get(self, model_cls: type[AnyModel], id_: int) -> AnyModel | None: """Get a Model object by its id or None if the id does not exist.""" - return self._fetch(model_cls, MatchQuery("id", id_)).get() + return self._get_results(model_cls, MatchQuery("id", id_)).get() class Index(NamedTuple): diff --git a/beets/library/library.py b/beets/library/library.py index ff31d13e3..f8d5595b1 100644 --- a/beets/library/library.py +++ b/beets/library/library.py @@ -148,7 +148,7 @@ class Library(dbcore.Database): if parsed_sort and not isinstance(parsed_sort, NullSort): sort = parsed_sort - return super()._fetch(model_cls, query, sort) + return super()._get_results(model_cls, query, sort) @staticmethod def get_default_album_sort(): diff --git a/test/dbcore/test_db.py b/test/dbcore/test_db.py index 7a6eece60..829919847 100644 --- a/test/dbcore/test_db.py +++ b/test/dbcore/test_db.py @@ -527,16 +527,16 @@ class ResultsIteratorTest(unittest.TestCase): self.db._connection().close() def test_iterate_once(self): - objs = self.db._fetch(ModelFixture1) + objs = self.db._get_results(ModelFixture1) assert len(list(objs)) == 2 def test_iterate_twice(self): - objs = self.db._fetch(ModelFixture1) + objs = self.db._get_results(ModelFixture1) list(objs) assert len(list(objs)) == 2 def test_concurrent_iterators(self): - results = self.db._fetch(ModelFixture1) + results = self.db._get_results(ModelFixture1) it1 = iter(results) it2 = iter(results) next(it1) @@ -545,43 +545,46 @@ class ResultsIteratorTest(unittest.TestCase): def test_slow_query(self): q = query.SubstringQuery("foo", "ba", False) - objs = self.db._fetch(ModelFixture1, q) + objs = self.db._get_results(ModelFixture1, q) assert len(list(objs)) == 2 def test_slow_query_negative(self): q = query.SubstringQuery("foo", "qux", False) - objs = self.db._fetch(ModelFixture1, q) + objs = self.db._get_results(ModelFixture1, q) assert len(list(objs)) == 0 def test_iterate_slow_sort(self): s = sort.SlowFieldSort("foo") - res = self.db._fetch(ModelFixture1, sort=s) + res = self.db._get_results(ModelFixture1, sort=s) objs = list(res) assert objs[0].foo == "bar" assert objs[1].foo == "baz" def test_unsorted_subscript(self): - objs = self.db._fetch(ModelFixture1) + objs = self.db._get_results(ModelFixture1) assert objs[0].foo == "baz" assert objs[1].foo == "bar" def test_slow_sort_subscript(self): s = sort.SlowFieldSort("foo") - objs = self.db._fetch(ModelFixture1, sort=s) + objs = self.db._get_results(ModelFixture1, sort=s) assert objs[0].foo == "bar" assert objs[1].foo == "baz" def test_length(self): - objs = self.db._fetch(ModelFixture1) + objs = self.db._get_results(ModelFixture1) assert len(objs) == 2 def test_out_of_range(self): - objs = self.db._fetch(ModelFixture1) + objs = self.db._get_results(ModelFixture1) with pytest.raises(IndexError): objs[100] def test_no_results(self): - assert self.db._fetch(ModelFixture1, query.FalseQuery()).get() is None + assert ( + self.db._get_results(ModelFixture1, query.FalseQuery()).get() + is None + ) class TestException: