From 3ffa83aaa00c5db483b9c37d29372b9b92d7932d Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 20:55:00 +0530 Subject: [PATCH 01/29] Task-2 RUF012 --- openlibrary/utils/schema.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openlibrary/utils/schema.py b/openlibrary/utils/schema.py index 075da45ee3f..20d2f1f13c1 100644 --- a/openlibrary/utils/schema.py +++ b/openlibrary/utils/schema.py @@ -1,3 +1,5 @@ +from typing import ClassVar + """utility to generate db schema for any database engine. (should go to web.py) """ @@ -94,7 +96,7 @@ def quote(self, value): class MySQLAdapter(AbstractAdapter): - native_types = { + native_types : ClassVar[dict[str,str]]= { 'serial': 'int auto_increment not null', 'integer': 'int', 'float': 'float', @@ -107,7 +109,7 @@ class MySQLAdapter(AbstractAdapter): 'binary': 'blob', 'boolean': 'boolean', } - constants = { + constants :ClassVar[dict[str,str]]= { 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP', 'CURRENT_DATE': 'CURRENT_DATE', 'CURRENT_TIME': 'CURRENT_TIME', @@ -121,7 +123,7 @@ def references_to_sql(self, column_name, value): class PostgresAdapter(AbstractAdapter): - native_types = { + native_types: ClassVar[dict[str,str]] = { 'serial': 'serial', 'integer': 'int', 'float': 'float', @@ -134,7 +136,7 @@ class PostgresAdapter(AbstractAdapter): 'binary': 'bytea', 'boolean': 'boolean', } - constants = { + constants: ClassVar[dict[str,str]] = { 'CURRENT_TIMESTAMP': 'current_timestamp', 'CURRENT_DATE': 'current_date', 'CURRENT_TIME': 'current_time', @@ -148,7 +150,7 @@ def references_to_sql(self, column_name, value): class SQLiteAdapter(AbstractAdapter): - native_types = { + native_types: ClassVar[dict[str,str]] = { 'serial': 'integer autoincrement', 'integer': 'integer', 'float': 'float', @@ -161,7 +163,7 @@ class SQLiteAdapter(AbstractAdapter): 'binary': 'blob', 'boolean': 'boolean', } - constants = { + constants : ClassVar[dict[str,str]] = { 'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP", 'CURRENT_DATE': "CURRENT_DATE", 'CURRENT_TIME': "CURRENT_TIME", From 78793a6782b48adb8402f12b0ad1b93ab8a5de67 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 20:55:49 +0530 Subject: [PATCH 02/29] Task-2 RUF012 --- openlibrary/tests/core/test_db.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 33caf42efaa..21f2c15382a 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,4 +1,5 @@ import web +from typing import ClassVar from openlibrary.core.booknotes import Booknotes from openlibrary.core.bookshelves import Bookshelves @@ -156,7 +157,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS = [ + READING_LOG_SETUP_ROWS : ClassVar[List[Dict[str, str|int]]]= [ { "username": "@kilgore_trout", "work_id": 1, @@ -176,15 +177,15 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ] - BOOKNOTES_SETUP_ROWS = [ + BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ] - RATINGS_SETUP_ROWS = [ + RATINGS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ] - OBSERVATIONS_SETUP_ROWS = [ + OBSERVATIONS_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -201,7 +202,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS = [ + EDITS_QUEUE_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", @@ -308,7 +309,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS = [ + BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ { "id": 1, "username": "@kilgore_trout", @@ -481,7 +482,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS = [ + SETUP_ROWS:ClassVar[List[Dict[str, str | int]]] = [ { 'username': '@billy_pilgrim', 'year': 2022, From da290a6ebad2200b1c14e0f01c63e01a094fd658 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:35:07 +0000 Subject: [PATCH 03/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 15 ++++++++------- openlibrary/utils/schema.py | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 21f2c15382a..4affd2956f6 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,6 +1,7 @@ -import web from typing import ClassVar +import web + from openlibrary.core.booknotes import Booknotes from openlibrary.core.bookshelves import Bookshelves from openlibrary.core.bookshelves_events import BookshelvesEvents @@ -157,7 +158,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS : ClassVar[List[Dict[str, str|int]]]= [ + READING_LOG_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -177,7 +178,7 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ] - BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ + BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ] @@ -185,7 +186,7 @@ class TestUsernameUpdate: {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ] - OBSERVATIONS_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ + OBSERVATIONS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -202,7 +203,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ + EDITS_QUEUE_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", @@ -309,7 +310,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ + BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ { "id": 1, "username": "@kilgore_trout", @@ -482,7 +483,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS:ClassVar[List[Dict[str, str | int]]] = [ + SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ { 'username': '@billy_pilgrim', 'year': 2022, diff --git a/openlibrary/utils/schema.py b/openlibrary/utils/schema.py index 20d2f1f13c1..99153d3c2df 100644 --- a/openlibrary/utils/schema.py +++ b/openlibrary/utils/schema.py @@ -96,7 +96,7 @@ def quote(self, value): class MySQLAdapter(AbstractAdapter): - native_types : ClassVar[dict[str,str]]= { + native_types: ClassVar[dict[str, str]] = { 'serial': 'int auto_increment not null', 'integer': 'int', 'float': 'float', @@ -109,7 +109,7 @@ class MySQLAdapter(AbstractAdapter): 'binary': 'blob', 'boolean': 'boolean', } - constants :ClassVar[dict[str,str]]= { + constants: ClassVar[dict[str, str]] = { 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP', 'CURRENT_DATE': 'CURRENT_DATE', 'CURRENT_TIME': 'CURRENT_TIME', @@ -123,7 +123,7 @@ def references_to_sql(self, column_name, value): class PostgresAdapter(AbstractAdapter): - native_types: ClassVar[dict[str,str]] = { + native_types: ClassVar[dict[str, str]] = { 'serial': 'serial', 'integer': 'int', 'float': 'float', @@ -136,7 +136,7 @@ class PostgresAdapter(AbstractAdapter): 'binary': 'bytea', 'boolean': 'boolean', } - constants: ClassVar[dict[str,str]] = { + constants: ClassVar[dict[str, str]] = { 'CURRENT_TIMESTAMP': 'current_timestamp', 'CURRENT_DATE': 'current_date', 'CURRENT_TIME': 'current_time', @@ -150,7 +150,7 @@ def references_to_sql(self, column_name, value): class SQLiteAdapter(AbstractAdapter): - native_types: ClassVar[dict[str,str]] = { + native_types: ClassVar[dict[str, str]] = { 'serial': 'integer autoincrement', 'integer': 'integer', 'float': 'float', @@ -163,7 +163,7 @@ class SQLiteAdapter(AbstractAdapter): 'binary': 'blob', 'boolean': 'boolean', } - constants : ClassVar[dict[str,str]] = { + constants: ClassVar[dict[str, str]] = { 'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP", 'CURRENT_DATE': "CURRENT_DATE", 'CURRENT_TIME': "CURRENT_TIME", From b3ce893fb70798ef36aa0bedfabaab84c7f91446 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 21:08:45 +0530 Subject: [PATCH 04/29] Task-2 RUF012 --- openlibrary/tests/core/test_db.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 21f2c15382a..165792e3a2a 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -157,7 +157,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS : ClassVar[List[Dict[str, str|int]]]= [ + READING_LOG_SETUP_ROWS : ClassVar[list[dict[str, str|int]]]= [ { "username": "@kilgore_trout", "work_id": 1, @@ -177,15 +177,15 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ] - BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ + BOOKNOTES_SETUP_ROWS: ClassVar[list[dict[str, str | int]]]= [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ] - RATINGS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + RATINGS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ] - OBSERVATIONS_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ + OBSERVATIONS_SETUP_ROWS :ClassVar[list[dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -202,7 +202,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS :ClassVar[List[Dict[str, str | int]]] = [ + EDITS_QUEUE_SETUP_ROWS :ClassVar[list[dict[str, str | int]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", @@ -309,7 +309,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]]= [ + BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]]= [ { "id": 1, "username": "@kilgore_trout", From 420c8a6966ef29d7a3a53774250140893c466dea Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 21:15:58 +0530 Subject: [PATCH 05/29] Task-2 RUF012 --- openlibrary/tests/core/test_db.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index a129535b6d1..f4050b13f10 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,4 @@ from typing import ClassVar - import web from openlibrary.core.booknotes import Booknotes @@ -158,11 +157,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: -<<<<<<< HEAD - READING_LOG_SETUP_ROWS : ClassVar[list[dict[str, str|int]]]= [ -======= READING_LOG_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ ->>>>>>> da290a6ebad2200b1c14e0f01c63e01a094fd658 { "username": "@kilgore_trout", "work_id": 1, @@ -182,11 +177,7 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ] -<<<<<<< HEAD - BOOKNOTES_SETUP_ROWS: ClassVar[list[dict[str, str | int]]]= [ -======= BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ ->>>>>>> da290a6ebad2200b1c14e0f01c63e01a094fd658 {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ] @@ -194,11 +185,7 @@ class TestUsernameUpdate: {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ] -<<<<<<< HEAD - OBSERVATIONS_SETUP_ROWS :ClassVar[list[dict[str, str | int]]] = [ -======= OBSERVATIONS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ ->>>>>>> da290a6ebad2200b1c14e0f01c63e01a094fd658 { "username": "@kilgore_trout", "work_id": 1, @@ -215,11 +202,7 @@ class TestUsernameUpdate: }, ] -<<<<<<< HEAD - EDITS_QUEUE_SETUP_ROWS :ClassVar[list[dict[str, str | int]]] = [ -======= EDITS_QUEUE_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ ->>>>>>> da290a6ebad2200b1c14e0f01c63e01a094fd658 { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", @@ -326,11 +309,7 @@ def test_update_username(self): class TestCheckIns: -<<<<<<< HEAD - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]]= [ -======= BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ ->>>>>>> da290a6ebad2200b1c14e0f01c63e01a094fd658 { "id": 1, "username": "@kilgore_trout", From 6b2e6f66004d99ba4f4181a6a8f0d441332cbfb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:47:02 +0000 Subject: [PATCH 06/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index f4050b13f10..ff7160578b5 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,4 +1,5 @@ from typing import ClassVar + import web from openlibrary.core.booknotes import Booknotes From f027ffb64285e095bb6da83ad608fc9e2e7c0595 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 21:21:46 +0530 Subject: [PATCH 07/29] Task-2 RUF012 --- openlibrary/tests/core/test_db.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index ff7160578b5..44a90435c22 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -158,7 +158,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + READING_LOG_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -178,7 +178,7 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ] - BOOKNOTES_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + BOOKNOTES_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ] @@ -186,7 +186,7 @@ class TestUsernameUpdate: {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ] - OBSERVATIONS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + OBSERVATIONS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ { "username": "@kilgore_trout", "work_id": 1, @@ -203,7 +203,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", @@ -310,7 +310,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ { "id": 1, "username": "@kilgore_trout", @@ -483,7 +483,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS: ClassVar[List[Dict[str, str | int]]] = [ + SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ { 'username': '@billy_pilgrim', 'year': 2022, From d468b764dc148a96d06b3ffe5ad416c2da329ccb Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Mon, 6 Jan 2025 21:28:29 +0530 Subject: [PATCH 08/29] Task-2 RUF012 --- openlibrary/tests/core/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 44a90435c22..0dd262ad904 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -203,7 +203,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int| None]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", From d4bc0352d9ba4e923726fcc7609867a0a7aee69f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:59:33 +0000 Subject: [PATCH 09/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 0dd262ad904..3478f882252 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -203,7 +203,7 @@ class TestUsernameUpdate: }, ] - EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int| None]]] = [ + EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int | None]]] = [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", "submitter": "@kilgore_trout", From 156f10425cb632a6ed7160a08ebfa7a2202613ce Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Thu, 23 Jan 2025 23:47:22 +0530 Subject: [PATCH 10/29] ruff RUF012 --- openlibrary/tests/core/test_db.py | 76 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 0dd262ad904..f7efb8f1ad3 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,4 +1,5 @@ -from typing import ClassVar +from collections.abc import Mapping +from typing import classVar import web @@ -158,7 +159,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + READING_LOG_SETUP_ROWS: classVar[tuple[Mapping[str,str|int], ...]]= ( { "username": "@kilgore_trout", "work_id": 1, @@ -177,16 +178,16 @@ class TestUsernameUpdate: "edition_id": 1, "bookshelf_id": 2, }, - ] - BOOKNOTES_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + ) + BOOKNOTES_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, - ] - RATINGS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + ) + RATINGS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, - ] - OBSERVATIONS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + ) + OBSERVATIONS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( { "username": "@kilgore_trout", "work_id": 1, @@ -201,31 +202,32 @@ class TestUsernameUpdate: "observation_type": 4, "observation_value": 1, }, - ] - - EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int| None]]] = [ - { - "title": "One Fish, Two Fish, Red Fish, Blue Fish", - "submitter": "@kilgore_trout", - "reviewer": None, - "url": "/works/merge?records=OL1W,OL2W,OL3W", - "status": 1, - }, - { - "title": "The Lorax", - "submitter": "@kilgore_trout", - "reviewer": "@billy_pilgrim", - "url": "/works/merge?records=OL4W,OL5W,OL6W", - "status": 2, - }, - { - "title": "Green Eggs and Ham", - "submitter": "@eliot_rosewater", - "reviewer": None, - "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", - "status": 1, - }, - ] + ) + + def get_editd_queue_setup_rows(cls) -> list[Mapping[str,str|int|None]]: + return [ + { + "title": "One Fish, Two Fish, Red Fish, Blue Fish", + "submitter": "@kilgore_trout", + "reviewer": None, + "url": "/works/merge?records=OL1W,OL2W,OL3W", + "status": 1, + }, + { + "title": "The Lorax", + "submitter": "@kilgore_trout", + "reviewer": "@billy_pilgrim", + "url": "/works/merge?records=OL4W,OL5W,OL6W", + "status": 2, + }, + { + "title": "Green Eggs and Ham", + "submitter": "@eliot_rosewater", + "reviewer": None, + "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", + "status": 1, + }, + ] @classmethod def setup_class(cls): @@ -310,7 +312,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + BOOKSHELVES_EVENTS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( { "id": 1, "username": "@kilgore_trout", @@ -359,7 +361,7 @@ class TestCheckIns: "event_type": 3, "event_date": "2019-10", }, - ] + ) @classmethod def setup_class(cls): @@ -483,7 +485,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [ + SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( { 'username': '@billy_pilgrim', 'year': 2022, @@ -502,7 +504,7 @@ class TestYearlyReadingGoals: 'target': 4, 'current': 4, }, - ] + ) TABLENAME = YearlyReadingGoals.TABLENAME From db0b2360b3cd5227313ceb63f2cdf83323c0651e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:21:46 +0000 Subject: [PATCH 11/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index e9681bcd25d..2ec3fa07347 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -159,7 +159,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS: classVar[tuple[Mapping[str,str|int], ...]]= ( + READING_LOG_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( { "username": "@kilgore_trout", "work_id": 1, @@ -179,15 +179,15 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ) - BOOKNOTES_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( + BOOKNOTES_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ) - RATINGS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( + RATINGS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ) - OBSERVATIONS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( + OBSERVATIONS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( { "username": "@kilgore_trout", "work_id": 1, @@ -204,7 +204,7 @@ class TestUsernameUpdate: }, ) - def get_edits_queue_setup_rows(cls) -> list[Mapping[str,str|int|None]]: + def get_edits_queue_setup_rows(cls) -> list[Mapping[str, str | int | None]]: return [ { "title": "One Fish, Two Fish, Red Fish, Blue Fish", @@ -312,7 +312,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( + BOOKSHELVES_EVENTS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( { "id": 1, "username": "@kilgore_trout", @@ -485,7 +485,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS : classVar[tuple[Mapping[str,str|int], ...]]= ( + SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( { 'username': '@billy_pilgrim', 'year': 2022, From aa86e8ad7d5382243c0a775809bf8880f8db5d30 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Thu, 23 Jan 2025 23:57:57 +0530 Subject: [PATCH 12/29] RUF012 --- openlibrary/tests/core/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index e9681bcd25d..a6cd369a784 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,5 @@ from collections.abc import Mapping -from typing import classVar +from typing import ClassVar import web From 9337a7c61702a4a4bedbbb31715bb78195ef9051 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:36:50 +0000 Subject: [PATCH 13/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 62a362d51e3..868b4d3f186 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,4 @@ from collections.abc import Mapping -from typing import ClassVar import web From 2165888e319025a3943fc9fd55d496badf3d8a5c Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 00:09:35 +0530 Subject: [PATCH 14/29] RUF012 --- openlibrary/tests/core/test_db.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 62a362d51e3..45a86b5aed9 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -159,7 +159,7 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + READING_LOG_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( { "username": "@kilgore_trout", "work_id": 1, @@ -179,15 +179,15 @@ class TestUsernameUpdate: "bookshelf_id": 2, }, ) - BOOKNOTES_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + BOOKNOTES_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, ) - RATINGS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + RATINGS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, ) - OBSERVATIONS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + OBSERVATIONS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( { "username": "@kilgore_trout", "work_id": 1, @@ -312,7 +312,7 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( { "id": 1, "username": "@kilgore_trout", @@ -485,7 +485,7 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS: classVar[tuple[Mapping[str, str | int], ...]] = ( + SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( { 'username': '@billy_pilgrim', 'year': 2022, From 1bc0aaaa19fe980faf4c0a7caa4f943679b8f02b Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 00:15:43 +0530 Subject: [PATCH 15/29] RUF012 --- openlibrary/tests/core/test_db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 3e5d64450d4..d8d3dc36d5b 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,4 +1,5 @@ from collections.abc import Mapping +from typing import CharVar import web From cc36cd9820387e8d5b22fa55d1a3104b5afa37a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:46:29 +0000 Subject: [PATCH 16/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index d8d3dc36d5b..3e5d64450d4 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,4 @@ from collections.abc import Mapping -from typing import CharVar import web From 65dee5c6e43db48b1ba0b19ba706682616bb2e1d Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 00:19:55 +0530 Subject: [PATCH 17/29] RUF012 --- openlibrary/tests/core/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index d8d3dc36d5b..45a86b5aed9 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,5 @@ from collections.abc import Mapping -from typing import CharVar +from typing import ClassVar import web From dd0f305d07fef7ab888146ec65546de6018e25fc Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 03:01:15 +0530 Subject: [PATCH 18/29] RUF012 --- openlibrary/tests/core/test_db.py | 128 +++++++++++++++--------------- 1 file changed, 63 insertions(+), 65 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 45a86b5aed9..6ec0b338b1a 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -1,5 +1,4 @@ -from collections.abc import Mapping -from typing import ClassVar +from types import MappingProxyType import web @@ -159,75 +158,74 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - { + READING_LOG_SETUP_ROWS=( + MappingProxyType({ "username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "bookshelf_id": 1, - }, - { + }), + MappingProxyType({ "username": "@kilgore_trout", "work_id": 2, "edition_id": 2, "bookshelf_id": 1, - }, - { + }), + MappingProxyType({ "username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "bookshelf_id": 2, - }, + }), ) - BOOKNOTES_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}, - {"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}, + BOOKNOTES_SETUP_ROWS=( + MappingProxyType({"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}), + MappingProxyType({"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}), ) - RATINGS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}, - {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}, - ) - OBSERVATIONS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - { + RATINGS_SETUP_ROWS=( + MappingProxyType({"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}), + MappingProxyType({"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}), + ) + OBSERVATIONS_SETUP_ROWS= ( + MappingProxyType({ "username": "@kilgore_trout", "work_id": 1, "edition_id": 3, "observation_type": 1, "observation_value": 2, - }, - { + }), + MappingProxyType({ "username": "@billy_pilgrim", "work_id": 2, "edition_id": 4, "observation_type": 4, "observation_value": 1, - }, + }), ) - def get_edits_queue_setup_rows(cls) -> list[Mapping[str, str | int | None]]: - return [ - { - "title": "One Fish, Two Fish, Red Fish, Blue Fish", - "submitter": "@kilgore_trout", - "reviewer": None, - "url": "/works/merge?records=OL1W,OL2W,OL3W", - "status": 1, - }, - { - "title": "The Lorax", - "submitter": "@kilgore_trout", - "reviewer": "@billy_pilgrim", - "url": "/works/merge?records=OL4W,OL5W,OL6W", - "status": 2, - }, - { - "title": "Green Eggs and Ham", - "submitter": "@eliot_rosewater", - "reviewer": None, - "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", - "status": 1, - }, - ] + EDITS_QUEUE_SETUP_ROWS=( + MappingProxyType({ + "title": "One Fish, Two Fish, Red Fish, Blue Fish", + "submitter": "@kilgore_trout", + "reviewer": None, + "url": "/works/merge?records=OL1W,OL2W,OL3W", + "status": 1, + }), + MappingProxyType({ + "title": "The Lorax", + "submitter": "@kilgore_trout", + "reviewer": "@billy_pilgrim", + "url": "/works/merge?records=OL4W,OL5W,OL6W", + "status": 2, + }), + MappingProxyType({ + "title": "Green Eggs and Ham", + "submitter": "@eliot_rosewater", + "reviewer": None, + "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", + "status": 1, + }), + ) @classmethod def setup_class(cls): @@ -312,55 +310,55 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - { + BOOKSHELVES_EVENTS_SETUP_ROWS= ( + MappingProxyType({ "id": 1, "username": "@kilgore_trout", "work_id": 1, "edition_id": 2, "event_type": 1, "event_date": "2022-04-17", - }, - { + }), + MappingProxyType({ "id": 2, "username": "@kilgore_trout", "work_id": 1, "edition_id": 2, "event_type": 2, "event_date": "2022-05-10", - }, - { + }), + MappingProxyType({ "id": 3, "username": "@kilgore_trout", "work_id": 1, "edition_id": 2, "event_type": 3, "event_date": "2022-06-20", - }, - { + }), + MappingProxyType({ "id": 4, "username": "@billy_pilgrim", "work_id": 3, "edition_id": 4, "event_type": 1, "event_date": "2020", - }, - { + }), + MappingProxyType({ "id": 5, "username": "@eliot_rosewater", "work_id": 3, "edition_id": 4, "event_type": 3, "event_date": "2019-08-20", - }, - { + }), + MappingProxyType({ "id": 6, "username": "@eliot_rosewater", "work_id": 3, "edition_id": 4, "event_type": 3, "event_date": "2019-10", - }, + }), ) @classmethod @@ -485,25 +483,25 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS: ClassVar[tuple[Mapping[str, str | int], ...]] = ( - { + SETUP_ROWS=( + MappingProxyType({ 'username': '@billy_pilgrim', 'year': 2022, 'target': 5, 'current': 6, - }, - { + }), + MappingProxyType({ 'username': '@billy_pilgrim', 'year': 2023, 'target': 7, 'current': 0, - }, - { + }), + MappingProxyType({ 'username': '@kilgore_trout', 'year': 2022, 'target': 4, 'current': 4, - }, + }), ) TABLENAME = YearlyReadingGoals.TABLENAME From 7ff015ca00b8e06a6fb15a38155097bb3c8dd844 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 21:32:20 +0000 Subject: [PATCH 19/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/tests/core/test_db.py | 316 +++++++++++++++++------------- 1 file changed, 184 insertions(+), 132 deletions(-) diff --git a/openlibrary/tests/core/test_db.py b/openlibrary/tests/core/test_db.py index 6ec0b338b1a..8ac2edd589c 100644 --- a/openlibrary/tests/core/test_db.py +++ b/openlibrary/tests/core/test_db.py @@ -158,74 +158,108 @@ def test_no_allow_delete_on_conflict(self): class TestUsernameUpdate: - READING_LOG_SETUP_ROWS=( - MappingProxyType({ - "username": "@kilgore_trout", - "work_id": 1, - "edition_id": 1, - "bookshelf_id": 1, - }), - MappingProxyType({ - "username": "@kilgore_trout", - "work_id": 2, - "edition_id": 2, - "bookshelf_id": 1, - }), - MappingProxyType({ - "username": "@billy_pilgrim", - "work_id": 1, - "edition_id": 1, - "bookshelf_id": 2, - }), + READING_LOG_SETUP_ROWS = ( + MappingProxyType( + { + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 1, + "bookshelf_id": 1, + } + ), + MappingProxyType( + { + "username": "@kilgore_trout", + "work_id": 2, + "edition_id": 2, + "bookshelf_id": 1, + } + ), + MappingProxyType( + { + "username": "@billy_pilgrim", + "work_id": 1, + "edition_id": 1, + "bookshelf_id": 2, + } + ), ) - BOOKNOTES_SETUP_ROWS=( - MappingProxyType({"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"}), - MappingProxyType({"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"}), + BOOKNOTES_SETUP_ROWS = ( + MappingProxyType( + { + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 1, + "notes": "Hello", + } + ), + MappingProxyType( + { + "username": "@billy_pilgrim", + "work_id": 1, + "edition_id": 1, + "notes": "World", + } + ), ) - RATINGS_SETUP_ROWS=( - MappingProxyType({"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4}), - MappingProxyType({"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2}), - ) - OBSERVATIONS_SETUP_ROWS= ( - MappingProxyType({ - "username": "@kilgore_trout", - "work_id": 1, - "edition_id": 3, - "observation_type": 1, - "observation_value": 2, - }), - MappingProxyType({ - "username": "@billy_pilgrim", - "work_id": 2, - "edition_id": 4, - "observation_type": 4, - "observation_value": 1, - }), + RATINGS_SETUP_ROWS = ( + MappingProxyType( + {"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4} + ), + MappingProxyType( + {"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2} + ), + ) + OBSERVATIONS_SETUP_ROWS = ( + MappingProxyType( + { + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 3, + "observation_type": 1, + "observation_value": 2, + } + ), + MappingProxyType( + { + "username": "@billy_pilgrim", + "work_id": 2, + "edition_id": 4, + "observation_type": 4, + "observation_value": 1, + } + ), ) - EDITS_QUEUE_SETUP_ROWS=( - MappingProxyType({ - "title": "One Fish, Two Fish, Red Fish, Blue Fish", - "submitter": "@kilgore_trout", - "reviewer": None, - "url": "/works/merge?records=OL1W,OL2W,OL3W", - "status": 1, - }), - MappingProxyType({ - "title": "The Lorax", - "submitter": "@kilgore_trout", - "reviewer": "@billy_pilgrim", - "url": "/works/merge?records=OL4W,OL5W,OL6W", - "status": 2, - }), - MappingProxyType({ - "title": "Green Eggs and Ham", - "submitter": "@eliot_rosewater", - "reviewer": None, - "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", - "status": 1, - }), - ) + EDITS_QUEUE_SETUP_ROWS = ( + MappingProxyType( + { + "title": "One Fish, Two Fish, Red Fish, Blue Fish", + "submitter": "@kilgore_trout", + "reviewer": None, + "url": "/works/merge?records=OL1W,OL2W,OL3W", + "status": 1, + } + ), + MappingProxyType( + { + "title": "The Lorax", + "submitter": "@kilgore_trout", + "reviewer": "@billy_pilgrim", + "url": "/works/merge?records=OL4W,OL5W,OL6W", + "status": 2, + } + ), + MappingProxyType( + { + "title": "Green Eggs and Ham", + "submitter": "@eliot_rosewater", + "reviewer": None, + "url": "/works/merge?records=OL10W,OL11W,OL12W,OL13W", + "status": 1, + } + ), + ) @classmethod def setup_class(cls): @@ -310,55 +344,67 @@ def test_update_username(self): class TestCheckIns: - BOOKSHELVES_EVENTS_SETUP_ROWS= ( - MappingProxyType({ - "id": 1, - "username": "@kilgore_trout", - "work_id": 1, - "edition_id": 2, - "event_type": 1, - "event_date": "2022-04-17", - }), - MappingProxyType({ - "id": 2, - "username": "@kilgore_trout", - "work_id": 1, - "edition_id": 2, - "event_type": 2, - "event_date": "2022-05-10", - }), - MappingProxyType({ - "id": 3, - "username": "@kilgore_trout", - "work_id": 1, - "edition_id": 2, - "event_type": 3, - "event_date": "2022-06-20", - }), - MappingProxyType({ - "id": 4, - "username": "@billy_pilgrim", - "work_id": 3, - "edition_id": 4, - "event_type": 1, - "event_date": "2020", - }), - MappingProxyType({ - "id": 5, - "username": "@eliot_rosewater", - "work_id": 3, - "edition_id": 4, - "event_type": 3, - "event_date": "2019-08-20", - }), - MappingProxyType({ - "id": 6, - "username": "@eliot_rosewater", - "work_id": 3, - "edition_id": 4, - "event_type": 3, - "event_date": "2019-10", - }), + BOOKSHELVES_EVENTS_SETUP_ROWS = ( + MappingProxyType( + { + "id": 1, + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 2, + "event_type": 1, + "event_date": "2022-04-17", + } + ), + MappingProxyType( + { + "id": 2, + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 2, + "event_type": 2, + "event_date": "2022-05-10", + } + ), + MappingProxyType( + { + "id": 3, + "username": "@kilgore_trout", + "work_id": 1, + "edition_id": 2, + "event_type": 3, + "event_date": "2022-06-20", + } + ), + MappingProxyType( + { + "id": 4, + "username": "@billy_pilgrim", + "work_id": 3, + "edition_id": 4, + "event_type": 1, + "event_date": "2020", + } + ), + MappingProxyType( + { + "id": 5, + "username": "@eliot_rosewater", + "work_id": 3, + "edition_id": 4, + "event_type": 3, + "event_date": "2019-08-20", + } + ), + MappingProxyType( + { + "id": 6, + "username": "@eliot_rosewater", + "work_id": 3, + "edition_id": 4, + "event_type": 3, + "event_date": "2019-10", + } + ), ) @classmethod @@ -483,25 +529,31 @@ def test_get_latest_event_date(self): class TestYearlyReadingGoals: - SETUP_ROWS=( - MappingProxyType({ - 'username': '@billy_pilgrim', - 'year': 2022, - 'target': 5, - 'current': 6, - }), - MappingProxyType({ - 'username': '@billy_pilgrim', - 'year': 2023, - 'target': 7, - 'current': 0, - }), - MappingProxyType({ - 'username': '@kilgore_trout', - 'year': 2022, - 'target': 4, - 'current': 4, - }), + SETUP_ROWS = ( + MappingProxyType( + { + 'username': '@billy_pilgrim', + 'year': 2022, + 'target': 5, + 'current': 6, + } + ), + MappingProxyType( + { + 'username': '@billy_pilgrim', + 'year': 2023, + 'target': 7, + 'current': 0, + } + ), + MappingProxyType( + { + 'username': '@kilgore_trout', + 'year': 2022, + 'target': 4, + 'current': 4, + } + ), ) TABLENAME = YearlyReadingGoals.TABLENAME From a9c0b856be69797a6f2b88a0b09fa3774ceb4397 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 03:26:24 +0530 Subject: [PATCH 20/29] RUF012 --- openlibrary/utils/schema.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/openlibrary/utils/schema.py b/openlibrary/utils/schema.py index 99153d3c2df..80e8d3632bf 100644 --- a/openlibrary/utils/schema.py +++ b/openlibrary/utils/schema.py @@ -1,8 +1,7 @@ -from typing import ClassVar - """utility to generate db schema for any database engine. (should go to web.py) """ +from types import MappingProxyType __all__ = [ "Column", @@ -96,7 +95,7 @@ def quote(self, value): class MySQLAdapter(AbstractAdapter): - native_types: ClassVar[dict[str, str]] = { + native_types = MappingProxyType({ 'serial': 'int auto_increment not null', 'integer': 'int', 'float': 'float', @@ -108,22 +107,22 @@ class MySQLAdapter(AbstractAdapter): 'date': 'date', 'binary': 'blob', 'boolean': 'boolean', - } - constants: ClassVar[dict[str, str]] = { + }) + constants = MappingProxyType({ 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP', 'CURRENT_DATE': 'CURRENT_DATE', 'CURRENT_TIME': 'CURRENT_TIME', 'CURRENT_UTC_TIMESTAMP': 'UTC_TIMESTAMP', 'CURRENT_UTC_DATE': 'UTC_DATE', 'CURRENT_UTC_TIME': 'UTC_TIME', - } + }) def references_to_sql(self, column_name, value): return {'constraint': f'foreign key ({column_name}) references {value}'} class PostgresAdapter(AbstractAdapter): - native_types: ClassVar[dict[str, str]] = { + native_types =MappingProxyType({ 'serial': 'serial', 'integer': 'int', 'float': 'float', @@ -135,22 +134,22 @@ class PostgresAdapter(AbstractAdapter): 'date': 'date', 'binary': 'bytea', 'boolean': 'boolean', - } - constants: ClassVar[dict[str, str]] = { + }) + constants = MappingProxyType({ 'CURRENT_TIMESTAMP': 'current_timestamp', 'CURRENT_DATE': 'current_date', 'CURRENT_TIME': 'current_time', 'CURRENT_UTC_TIMESTAMP': "(current_timestamp at time zone 'utc')", 'CURRENT_UTC_DATE': "(date (current_timestamp at timezone 'utc'))", 'CURRENT_UTC_TIME': "(current_time at time zone 'utc')", - } + }) def references_to_sql(self, column_name, value): return 'references ' + value class SQLiteAdapter(AbstractAdapter): - native_types: ClassVar[dict[str, str]] = { + native_types = MappingProxyType({ 'serial': 'integer autoincrement', 'integer': 'integer', 'float': 'float', @@ -162,15 +161,15 @@ class SQLiteAdapter(AbstractAdapter): 'date': 'date', 'binary': 'blob', 'boolean': 'boolean', - } - constants: ClassVar[dict[str, str]] = { + }) + constants = MappingProxyType({ 'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP", 'CURRENT_DATE': "CURRENT_DATE", 'CURRENT_TIME': "CURRENT_TIME", 'CURRENT_UTC_TIMESTAMP': "CURRENT_TIMESTAMP", 'CURRENT_UTC_DATE': "CURRENT_DATE", 'CURRENT_UTC_TIME': "CURRENT_TIME", - } + }) register_adapter('mysql', MySQLAdapter) From e6f894b86f80dfa7f335ad6ff9aa537c1f0e92fc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 21:59:02 +0000 Subject: [PATCH 21/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/utils/schema.py | 139 ++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/openlibrary/utils/schema.py b/openlibrary/utils/schema.py index 80e8d3632bf..14b9b2c1b16 100644 --- a/openlibrary/utils/schema.py +++ b/openlibrary/utils/schema.py @@ -1,6 +1,7 @@ """utility to generate db schema for any database engine. (should go to web.py) """ + from types import MappingProxyType __all__ = [ @@ -95,81 +96,93 @@ def quote(self, value): class MySQLAdapter(AbstractAdapter): - native_types = MappingProxyType({ - 'serial': 'int auto_increment not null', - 'integer': 'int', - 'float': 'float', - 'string': 'varchar', - 'text': 'text', - 'datetime': 'datetime', - 'timestamp': 'datetime', - 'time': 'time', - 'date': 'date', - 'binary': 'blob', - 'boolean': 'boolean', - }) - constants = MappingProxyType({ - 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP', - 'CURRENT_DATE': 'CURRENT_DATE', - 'CURRENT_TIME': 'CURRENT_TIME', - 'CURRENT_UTC_TIMESTAMP': 'UTC_TIMESTAMP', - 'CURRENT_UTC_DATE': 'UTC_DATE', - 'CURRENT_UTC_TIME': 'UTC_TIME', - }) + native_types = MappingProxyType( + { + 'serial': 'int auto_increment not null', + 'integer': 'int', + 'float': 'float', + 'string': 'varchar', + 'text': 'text', + 'datetime': 'datetime', + 'timestamp': 'datetime', + 'time': 'time', + 'date': 'date', + 'binary': 'blob', + 'boolean': 'boolean', + } + ) + constants = MappingProxyType( + { + 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP', + 'CURRENT_DATE': 'CURRENT_DATE', + 'CURRENT_TIME': 'CURRENT_TIME', + 'CURRENT_UTC_TIMESTAMP': 'UTC_TIMESTAMP', + 'CURRENT_UTC_DATE': 'UTC_DATE', + 'CURRENT_UTC_TIME': 'UTC_TIME', + } + ) def references_to_sql(self, column_name, value): return {'constraint': f'foreign key ({column_name}) references {value}'} class PostgresAdapter(AbstractAdapter): - native_types =MappingProxyType({ - 'serial': 'serial', - 'integer': 'int', - 'float': 'float', - 'string': 'character varying', - 'text': 'text', - 'datetime': 'timestamp', - 'timestamp': 'timestamp', - 'time': 'time', - 'date': 'date', - 'binary': 'bytea', - 'boolean': 'boolean', - }) - constants = MappingProxyType({ - 'CURRENT_TIMESTAMP': 'current_timestamp', - 'CURRENT_DATE': 'current_date', - 'CURRENT_TIME': 'current_time', - 'CURRENT_UTC_TIMESTAMP': "(current_timestamp at time zone 'utc')", - 'CURRENT_UTC_DATE': "(date (current_timestamp at timezone 'utc'))", - 'CURRENT_UTC_TIME': "(current_time at time zone 'utc')", - }) + native_types = MappingProxyType( + { + 'serial': 'serial', + 'integer': 'int', + 'float': 'float', + 'string': 'character varying', + 'text': 'text', + 'datetime': 'timestamp', + 'timestamp': 'timestamp', + 'time': 'time', + 'date': 'date', + 'binary': 'bytea', + 'boolean': 'boolean', + } + ) + constants = MappingProxyType( + { + 'CURRENT_TIMESTAMP': 'current_timestamp', + 'CURRENT_DATE': 'current_date', + 'CURRENT_TIME': 'current_time', + 'CURRENT_UTC_TIMESTAMP': "(current_timestamp at time zone 'utc')", + 'CURRENT_UTC_DATE': "(date (current_timestamp at timezone 'utc'))", + 'CURRENT_UTC_TIME': "(current_time at time zone 'utc')", + } + ) def references_to_sql(self, column_name, value): return 'references ' + value class SQLiteAdapter(AbstractAdapter): - native_types = MappingProxyType({ - 'serial': 'integer autoincrement', - 'integer': 'integer', - 'float': 'float', - 'string': 'varchar', - 'text': 'text', - 'datetime': 'datetime', - 'timestamp': 'datetime', - 'time': 'datetime', - 'date': 'date', - 'binary': 'blob', - 'boolean': 'boolean', - }) - constants = MappingProxyType({ - 'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP", - 'CURRENT_DATE': "CURRENT_DATE", - 'CURRENT_TIME': "CURRENT_TIME", - 'CURRENT_UTC_TIMESTAMP': "CURRENT_TIMESTAMP", - 'CURRENT_UTC_DATE': "CURRENT_DATE", - 'CURRENT_UTC_TIME': "CURRENT_TIME", - }) + native_types = MappingProxyType( + { + 'serial': 'integer autoincrement', + 'integer': 'integer', + 'float': 'float', + 'string': 'varchar', + 'text': 'text', + 'datetime': 'datetime', + 'timestamp': 'datetime', + 'time': 'datetime', + 'date': 'date', + 'binary': 'blob', + 'boolean': 'boolean', + } + ) + constants = MappingProxyType( + { + 'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP", + 'CURRENT_DATE': "CURRENT_DATE", + 'CURRENT_TIME': "CURRENT_TIME", + 'CURRENT_UTC_TIMESTAMP': "CURRENT_TIMESTAMP", + 'CURRENT_UTC_DATE': "CURRENT_DATE", + 'CURRENT_UTC_TIME': "CURRENT_TIME", + } + ) register_adapter('mysql', MySQLAdapter) From 11fd34f236f8a3bc69d7baf239bc8c5e4e94b6e0 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 10:16:30 +0530 Subject: [PATCH 22/29] RUF012 --- .../plugins/worksearch/schemes/editions.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index 5130834bc6a..414e9552212 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -1,5 +1,7 @@ import logging from datetime import datetime +from typing import Mapping, Set +from types import MappingProxyType from openlibrary.plugins.worksearch.schemes import SearchScheme @@ -10,8 +12,9 @@ # directly, but it's still useful for somethings (eg editions have a custom # sort logic). class EditionSearchScheme(SearchScheme): - universe = ['type:work'] - all_fields = { + # Keep instance variables without overriding with ClassVar + universe = ('type:work') + all_fields = frozenset( "key", "title", "subtitle", @@ -29,9 +32,9 @@ class EditionSearchScheme(SearchScheme): "publish_year", "language", "publisher_facet", - } - facet_fields: set[str] = set() - field_name_map = { + ) + facet_fields: set[str] = frozenset() + field_name_map: Mapping[str, str] = MappingProxyType({ 'publishers': 'publisher', 'subtitle': 'alternative_subtitle', 'title': 'alternative_title', @@ -39,8 +42,8 @@ class EditionSearchScheme(SearchScheme): # This is private because we'll change it to a multi-valued field instead of a # plain string at the next opportunity, which will make it much more usable. '_ia_collection': 'ia_collection_s', - } - sorts = { + }) + sorts : Mapping[str, str] = MappingProxyType({ 'old': 'def(publish_year, 9999) asc', 'new': 'publish_year desc', 'title': 'title_sort asc', @@ -58,9 +61,9 @@ class EditionSearchScheme(SearchScheme): 'random desc': 'random_1 desc', 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', - } - default_fetched_fields: set[str] = set() - facet_rewrites = {} + }) + default_fetched_fields: set[str] = frozenset() + facet_rewrites:Mapping[tuple[str, str], str] = MappingProxyType({}) def is_search_field(self, field: str): return super().is_search_field(field) or field.startswith('id_') From b1f51bc5c04c4193af189da4c2ea474fb3c334fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Jan 2025 04:47:36 +0000 Subject: [PATCH 23/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../plugins/worksearch/schemes/editions.py | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index 414e9552212..cd3ba1659ab 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -1,6 +1,6 @@ import logging +from collections.abc import Mapping from datetime import datetime -from typing import Mapping, Set from types import MappingProxyType from openlibrary.plugins.worksearch.schemes import SearchScheme @@ -13,7 +13,7 @@ # sort logic). class EditionSearchScheme(SearchScheme): # Keep instance variables without overriding with ClassVar - universe = ('type:work') + universe = 'type:work' all_fields = frozenset( "key", "title", @@ -34,36 +34,40 @@ class EditionSearchScheme(SearchScheme): "publisher_facet", ) facet_fields: set[str] = frozenset() - field_name_map: Mapping[str, str] = MappingProxyType({ - 'publishers': 'publisher', - 'subtitle': 'alternative_subtitle', - 'title': 'alternative_title', - # "Private" fields - # This is private because we'll change it to a multi-valued field instead of a - # plain string at the next opportunity, which will make it much more usable. - '_ia_collection': 'ia_collection_s', - }) - sorts : Mapping[str, str] = MappingProxyType({ - 'old': 'def(publish_year, 9999) asc', - 'new': 'publish_year desc', - 'title': 'title_sort asc', - # Ebook access - 'ebook_access': 'ebook_access desc', - 'ebook_access asc': 'ebook_access asc', - 'ebook_access desc': 'ebook_access desc', - # Key - 'key': 'key asc', - 'key asc': 'key asc', - 'key desc': 'key desc', - # Random - 'random': 'random_1 asc', - 'random asc': 'random_1 asc', - 'random desc': 'random_1 desc', - 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', - 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', - }) + field_name_map: Mapping[str, str] = MappingProxyType( + { + 'publishers': 'publisher', + 'subtitle': 'alternative_subtitle', + 'title': 'alternative_title', + # "Private" fields + # This is private because we'll change it to a multi-valued field instead of a + # plain string at the next opportunity, which will make it much more usable. + '_ia_collection': 'ia_collection_s', + } + ) + sorts: Mapping[str, str] = MappingProxyType( + { + 'old': 'def(publish_year, 9999) asc', + 'new': 'publish_year desc', + 'title': 'title_sort asc', + # Ebook access + 'ebook_access': 'ebook_access desc', + 'ebook_access asc': 'ebook_access asc', + 'ebook_access desc': 'ebook_access desc', + # Key + 'key': 'key asc', + 'key asc': 'key asc', + 'key desc': 'key desc', + # Random + 'random': 'random_1 asc', + 'random asc': 'random_1 asc', + 'random desc': 'random_1 desc', + 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', + 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', + } + ) default_fetched_fields: set[str] = frozenset() - facet_rewrites:Mapping[tuple[str, str], str] = MappingProxyType({}) + facet_rewrites: Mapping[tuple[str, str], str] = MappingProxyType({}) def is_search_field(self, field: str): return super().is_search_field(field) or field.startswith('id_') From b4beed5ca58d0f939ae584ffbd3a4f2cd91633ae Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 10:31:15 +0530 Subject: [PATCH 24/29] RUF012 --- .../plugins/worksearch/schemes/editions.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index 414e9552212..82f4e3ab668 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -1,6 +1,6 @@ import logging from datetime import datetime -from typing import Mapping, Set +from typing import Mapping, Set, ClassVar from types import MappingProxyType from openlibrary.plugins.worksearch.schemes import SearchScheme @@ -13,8 +13,8 @@ # sort logic). class EditionSearchScheme(SearchScheme): # Keep instance variables without overriding with ClassVar - universe = ('type:work') - all_fields = frozenset( + universe = frozenset(['type:work']) + all_fields = frozenset([ "key", "title", "subtitle", @@ -32,9 +32,9 @@ class EditionSearchScheme(SearchScheme): "publish_year", "language", "publisher_facet", - ) - facet_fields: set[str] = frozenset() - field_name_map: Mapping[str, str] = MappingProxyType({ + ]) + facet_fields: ClassVar[set[str]] = frozenset() + field_name_map: ClassVar[dict[str, str]] = dict(MappingProxyType({ 'publishers': 'publisher', 'subtitle': 'alternative_subtitle', 'title': 'alternative_title', @@ -42,8 +42,8 @@ class EditionSearchScheme(SearchScheme): # This is private because we'll change it to a multi-valued field instead of a # plain string at the next opportunity, which will make it much more usable. '_ia_collection': 'ia_collection_s', - }) - sorts : Mapping[str, str] = MappingProxyType({ + })) + sorts:ClassVar[dict[str, str]] = dict(MappingProxyType({ 'old': 'def(publish_year, 9999) asc', 'new': 'publish_year desc', 'title': 'title_sort asc', @@ -61,9 +61,9 @@ class EditionSearchScheme(SearchScheme): 'random desc': 'random_1 desc', 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', - }) - default_fetched_fields: set[str] = frozenset() - facet_rewrites:Mapping[tuple[str, str], str] = MappingProxyType({}) + })) + default_fetched_fields: ClassVar[frozenset]= frozenset() + facet_rewrites: ClassVar[dict[tuple[str, str], str]]= {} def is_search_field(self, field: str): return super().is_search_field(field) or field.startswith('id_') From bbb88806c5926aeda0a75c344de809e7bb61b323 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Jan 2025 05:03:13 +0000 Subject: [PATCH 25/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/plugins/worksearch/schemes/editions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index b0f3543d167..0ea63db246c 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -73,7 +73,7 @@ class EditionSearchScheme(SearchScheme): 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', })) default_fetched_fields: ClassVar[frozenset]= frozenset() - facet_rewrites: ClassVar[dict[tuple[str, str], str]]= {} + facet_rewrites: ClassVar[dict[tuple[str, str], str]]= {} ======= ) facet_fields: set[str] = frozenset() From a66a078ec58b65bededdef9ef7f9536fef36a3d3 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 10:38:24 +0530 Subject: [PATCH 26/29] RUF012 --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3e12e853bfe..847049191ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,6 @@ ignore = [ "PLW2901", "RUF001", "RUF005", - "RUF012", "SIM108", "SIM115", "SLF001", From 528abf1fce2fe3e52ffdcf40f427830054e52e1e Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 10:38:35 +0530 Subject: [PATCH 27/29] RUF012 --- .../plugins/worksearch/schemes/editions.py | 90 +++---------------- 1 file changed, 14 insertions(+), 76 deletions(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index b0f3543d167..ef1329efea6 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -1,49 +1,25 @@ import logging -from collections.abc import Mapping from datetime import datetime -<<<<<<< HEAD from typing import Mapping, Set, ClassVar -======= ->>>>>>> b1f51bc5c04c4193af189da4c2ea474fb3c334fd from types import MappingProxyType - from openlibrary.plugins.worksearch.schemes import SearchScheme logger = logging.getLogger("openlibrary.worksearch") - # Kind of mostly a stub for now since you can't really search editions -# directly, but it's still useful for somethings (eg editions have a custom +# directly, but it's still useful for somethings (e.g., editions have a custom # sort logic). class EditionSearchScheme(SearchScheme): - # Keep instance variables without overriding with ClassVar -<<<<<<< HEAD universe = frozenset(['type:work']) + all_fields = frozenset([ -======= - universe = 'type:work' - all_fields = frozenset( ->>>>>>> b1f51bc5c04c4193af189da4c2ea474fb3c334fd - "key", - "title", - "subtitle", - "alternative_title", - "alternative_subtitle", - "cover_i", - "ebook_access", - "publish_date", - "lccn", - "ia", - "isbn", - "publisher", - "has_fulltext", - "title_suggest", - "publish_year", - "language", - "publisher_facet", -<<<<<<< HEAD + "key", "title", "subtitle", "alternative_title", "alternative_subtitle", + "cover_i", "ebook_access", "publish_date", "lccn", "ia", "isbn", "publisher", + "has_fulltext", "title_suggest", "publish_year", "language", "publisher_facet", ]) + facet_fields: ClassVar[set[str]] = frozenset() + field_name_map: ClassVar[dict[str, str]] = dict(MappingProxyType({ 'publishers': 'publisher', 'subtitle': 'alternative_subtitle', @@ -53,65 +29,27 @@ class EditionSearchScheme(SearchScheme): # plain string at the next opportunity, which will make it much more usable. '_ia_collection': 'ia_collection_s', })) - sorts:ClassVar[dict[str, str]] = dict(MappingProxyType({ + + sorts: ClassVar[dict[str, str]] = dict(MappingProxyType({ 'old': 'def(publish_year, 9999) asc', 'new': 'publish_year desc', 'title': 'title_sort asc', - # Ebook access 'ebook_access': 'ebook_access desc', 'ebook_access asc': 'ebook_access asc', 'ebook_access desc': 'ebook_access desc', - # Key 'key': 'key asc', 'key asc': 'key asc', 'key desc': 'key desc', - # Random 'random': 'random_1 asc', 'random asc': 'random_1 asc', 'random desc': 'random_1 desc', 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', })) - default_fetched_fields: ClassVar[frozenset]= frozenset() - facet_rewrites: ClassVar[dict[tuple[str, str], str]]= {} -======= - ) - facet_fields: set[str] = frozenset() - field_name_map: Mapping[str, str] = MappingProxyType( - { - 'publishers': 'publisher', - 'subtitle': 'alternative_subtitle', - 'title': 'alternative_title', - # "Private" fields - # This is private because we'll change it to a multi-valued field instead of a - # plain string at the next opportunity, which will make it much more usable. - '_ia_collection': 'ia_collection_s', - } - ) - sorts: Mapping[str, str] = MappingProxyType( - { - 'old': 'def(publish_year, 9999) asc', - 'new': 'publish_year desc', - 'title': 'title_sort asc', - # Ebook access - 'ebook_access': 'ebook_access desc', - 'ebook_access asc': 'ebook_access asc', - 'ebook_access desc': 'ebook_access desc', - # Key - 'key': 'key asc', - 'key asc': 'key asc', - 'key desc': 'key desc', - # Random - 'random': 'random_1 asc', - 'random asc': 'random_1 asc', - 'random desc': 'random_1 desc', - 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', - 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', - } - ) - default_fetched_fields: set[str] = frozenset() - facet_rewrites: Mapping[tuple[str, str], str] = MappingProxyType({}) ->>>>>>> b1f51bc5c04c4193af189da4c2ea474fb3c334fd + + default_fetched_fields: ClassVar[frozenset] = frozenset() + facet_rewrites: ClassVar[dict[tuple[str, str], str]] = {} - def is_search_field(self, field: str): + def is_search_field(self, field: str) -> bool: + """Check if the field is a valid search field, including fields starting with 'id_'.""" return super().is_search_field(field) or field.startswith('id_') From 95fd99f98e9c1430f031540ae82efb66b558d824 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Jan 2025 05:11:27 +0000 Subject: [PATCH 28/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../plugins/worksearch/schemes/editions.py | 98 ++++++++++++------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/openlibrary/plugins/worksearch/schemes/editions.py b/openlibrary/plugins/worksearch/schemes/editions.py index ef1329efea6..f490ec9ed48 100644 --- a/openlibrary/plugins/worksearch/schemes/editions.py +++ b/openlibrary/plugins/worksearch/schemes/editions.py @@ -1,52 +1,78 @@ import logging from datetime import datetime -from typing import Mapping, Set, ClassVar from types import MappingProxyType +from typing import ClassVar + from openlibrary.plugins.worksearch.schemes import SearchScheme logger = logging.getLogger("openlibrary.worksearch") + # Kind of mostly a stub for now since you can't really search editions # directly, but it's still useful for somethings (e.g., editions have a custom # sort logic). class EditionSearchScheme(SearchScheme): universe = frozenset(['type:work']) - - all_fields = frozenset([ - "key", "title", "subtitle", "alternative_title", "alternative_subtitle", - "cover_i", "ebook_access", "publish_date", "lccn", "ia", "isbn", "publisher", - "has_fulltext", "title_suggest", "publish_year", "language", "publisher_facet", - ]) - + + all_fields = frozenset( + [ + "key", + "title", + "subtitle", + "alternative_title", + "alternative_subtitle", + "cover_i", + "ebook_access", + "publish_date", + "lccn", + "ia", + "isbn", + "publisher", + "has_fulltext", + "title_suggest", + "publish_year", + "language", + "publisher_facet", + ] + ) + facet_fields: ClassVar[set[str]] = frozenset() - - field_name_map: ClassVar[dict[str, str]] = dict(MappingProxyType({ - 'publishers': 'publisher', - 'subtitle': 'alternative_subtitle', - 'title': 'alternative_title', - # "Private" fields - # This is private because we'll change it to a multi-valued field instead of a - # plain string at the next opportunity, which will make it much more usable. - '_ia_collection': 'ia_collection_s', - })) - - sorts: ClassVar[dict[str, str]] = dict(MappingProxyType({ - 'old': 'def(publish_year, 9999) asc', - 'new': 'publish_year desc', - 'title': 'title_sort asc', - 'ebook_access': 'ebook_access desc', - 'ebook_access asc': 'ebook_access asc', - 'ebook_access desc': 'ebook_access desc', - 'key': 'key asc', - 'key asc': 'key asc', - 'key desc': 'key desc', - 'random': 'random_1 asc', - 'random asc': 'random_1 asc', - 'random desc': 'random_1 desc', - 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', - 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', - })) - + + field_name_map: ClassVar[dict[str, str]] = dict( + MappingProxyType( + { + 'publishers': 'publisher', + 'subtitle': 'alternative_subtitle', + 'title': 'alternative_title', + # "Private" fields + # This is private because we'll change it to a multi-valued field instead of a + # plain string at the next opportunity, which will make it much more usable. + '_ia_collection': 'ia_collection_s', + } + ) + ) + + sorts: ClassVar[dict[str, str]] = dict( + MappingProxyType( + { + 'old': 'def(publish_year, 9999) asc', + 'new': 'publish_year desc', + 'title': 'title_sort asc', + 'ebook_access': 'ebook_access desc', + 'ebook_access asc': 'ebook_access asc', + 'ebook_access desc': 'ebook_access desc', + 'key': 'key asc', + 'key asc': 'key asc', + 'key desc': 'key desc', + 'random': 'random_1 asc', + 'random asc': 'random_1 asc', + 'random desc': 'random_1 desc', + 'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', + 'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', + } + ) + ) + default_fetched_fields: ClassVar[frozenset] = frozenset() facet_rewrites: ClassVar[dict[tuple[str, str], str]] = {} From 968468354cba12e62e13eb844812c6ba712a3439 Mon Sep 17 00:00:00 2001 From: ananyakaligal Date: Fri, 24 Jan 2025 10:45:36 +0530 Subject: [PATCH 29/29] RUF012 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 847049191ae..3e12e853bfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,7 @@ ignore = [ "PLW2901", "RUF001", "RUF005", + "RUF012", "SIM108", "SIM115", "SLF001",