From bbedf5b3fb78002f42cf6fc5ba87514f2faa7620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Fri, 1 Aug 2025 17:46:31 +0100 Subject: [PATCH] db: replace _get with from_id --- beets/dbcore/db.py | 4 ++-- beets/library/library.py | 4 ++-- beets/ui/__init__.py | 2 +- test/test_dbcore.py | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 6ee880597..1c7cf47da 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -652,7 +652,7 @@ class Model(ABC, Generic[D]): if not self._dirty and self.db.revision == self._revision: # Exit early return - stored_obj = self.db._get(type(self), self.id) + stored_obj = self.db.from_id(type(self), self.id) assert stored_obj is not None, f"object {self.id} not in DB" self._values_fixed = LazyConvertDict(self) self._values_flex = LazyConvertDict(self) @@ -1306,7 +1306,7 @@ class Database: sort if sort.is_slow() else None, # Slow sort component. ) - def _get( + def from_id( self, model_cls: type[AnyModel], id, diff --git a/beets/library/library.py b/beets/library/library.py index 7370f7ecd..0f3b6adbd 100644 --- a/beets/library/library.py +++ b/beets/library/library.py @@ -131,7 +131,7 @@ class Library(dbcore.Database): Return `None` if no match is found. """ - return self._get(Item, id) + return self.from_id(Item, id) def get_album(self, item_or_id): """Given an album ID or an item associated with an album, return @@ -145,4 +145,4 @@ class Library(dbcore.Database): album_id = item_or_id.album_id if album_id is None: return None - return self._get(Album, album_id) + return self.from_id(Album, album_id) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index cfd8b6bd7..664531359 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -1073,7 +1073,7 @@ def show_model_changes( restrict the detection to. `always` indicates whether the object is always identified, regardless of whether any changes are present. """ - old = old or new._db._get(type(new), new.id) + old = old or new._db.from_id(type(new), new.id) # Keep the formatted views around instead of re-creating them in each # iteration step diff --git a/test/test_dbcore.py b/test/test_dbcore.py index 653adf298..ff208c13e 100644 --- a/test/test_dbcore.py +++ b/test/test_dbcore.py @@ -310,7 +310,7 @@ class ModelTest(unittest.TestCase): def test_retrieve_by_id(self): model = ModelFixture1() model.add(self.db) - other_model = self.db._get(ModelFixture1, model.id) + other_model = self.db.from_id(ModelFixture1, model.id) assert model.id == other_model.id def test_store_and_retrieve_flexattr(self): @@ -319,7 +319,7 @@ class ModelTest(unittest.TestCase): model.foo = "bar" model.store() - other_model = self.db._get(ModelFixture1, model.id) + other_model = self.db.from_id(ModelFixture1, model.id) assert other_model.foo == "bar" def test_delete_flexattr(self): @@ -342,11 +342,11 @@ class ModelTest(unittest.TestCase): model.foo = "bar" model.store() - model = self.db._get(ModelFixture1, model.id) + model = self.db.from_id(ModelFixture1, model.id) del model["foo"] model.store() - model = self.db._get(ModelFixture1, model.id) + model = self.db.from_id(ModelFixture1, model.id) assert "foo" not in model def test_delete_non_existent_attribute(self): @@ -387,7 +387,7 @@ class ModelTest(unittest.TestCase): model1["flex_field"] = True model1.add(self.db) - model2 = self.db._get(ModelFixture1, model1.id) + model2 = self.db.from_id(ModelFixture1, model1.id) assert "flex_field" in model2 del model1["flex_field"]