Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RUF012) Fixed mutable class Defaults- Task 4 #10278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions openlibrary/plugins/openlibrary/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A lightweight version of github.com/internetarchive/bookserver
"""

from typing import ClassVar

import lxml.etree as ET

from infogami.infobase.utils import parse_datetime
Expand All @@ -16,7 +18,7 @@ class OPDS:
xmlns_bibo = 'http://purl.org/ontology/bibo/'
xmlns_xsi = 'http://www.w3.org/2001/XMLSchema-instance'

nsmap = {
nsmap: ClassVar[dict[None | str, str]] = {
None: xmlns_atom,
'dcterms': xmlns_dcterms,
'opds': xmlns_opds,
Expand All @@ -32,7 +34,7 @@ class OPDS:
bibo = "{%s}" % xmlns_bibo
xsi = "{%s}" % xmlns_xsi

fileExtMap = {
fileExtMap: ClassVar[dict[str, str]] = {
'pdf': 'application/pdf',
'epub': 'application/epub+zip',
'mobi': 'application/x-mobipocket-ebook',
Expand Down
10 changes: 7 additions & 3 deletions openlibrary/plugins/upstream/mybooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import TYPE_CHECKING, Final, Literal, cast
from typing import TYPE_CHECKING, ClassVar, Final, Literal, cast

import web
from web.template import TemplateResult
Expand Down Expand Up @@ -369,7 +369,11 @@ def get_patrons_work_read_status(username: str, work_key: str) -> int | None:
@public
class MyBooksTemplate:
# Reading log shelves
READING_LOG_KEYS = {"currently-reading", "want-to-read", "already-read"}
READING_LOG_KEYS: ClassVar[set[str]] = {
"currently-reading",
"want-to-read",
"already-read",
}

# Keys that can be accessed when not logged in
PUBLIC_KEYS = READING_LOG_KEYS | {"lists", "list"} | {"mybooks"}
Expand Down Expand Up @@ -454,7 +458,7 @@ class ReadingLog:
# Constants
PRESET_SHELVES = Literal["Want to Read", "Already Read", "Currently Reading"]
READING_LOG_KEYS = Literal["want-to-read", "already-read", "currently-reading"]
READING_LOG_KEY_TO_SHELF: dict[READING_LOG_KEYS, PRESET_SHELVES] = {
READING_LOG_KEY_TO_SHELF: ClassVar[dict[READING_LOG_KEYS, PRESET_SHELVES]] = {
"want-to-read": "Want to Read",
"already-read": "Already Read",
"currently-reading": "Currently Reading",
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/tests/solr/test_update.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar

import pytest

from openlibrary.core.ratings import WorkRatingsSummary
Expand Down Expand Up @@ -60,8 +62,8 @@ def make_work(**kw):
class FakeDataProvider(DataProvider):
"""Stub data_provider and methods which are used by build_data."""

docs: list = []
docs_by_key: dict = {}
docs: ClassVar[list] = []
docs_by_key: ClassVar[dict] = {}

def __init__(self, docs=None):
docs = docs or []
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/tests/solr/updater/test_work.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar

import pytest

from openlibrary.solr.updater.work import (
Expand Down Expand Up @@ -357,7 +359,7 @@ def test_author_info(self):
assert d.author_alternative_name == {"Author 1"}

# {'Test name': (doc_lccs, solr_lccs, sort_lcc_index)}
LCC_TESTS = {
LCC_TESTS: ClassVar[dict[str, tuple[list[str], list[str] | None, int | None]]] = {
'Remove dupes': (['A', 'A'], ['A--0000.00000000'], 0),
'Ignores garbage': (['$9.99'], None, None),
'Handles none': ([], None, None),
Expand Down Expand Up @@ -406,7 +408,7 @@ def test_lccs(self, doc_lccs, solr_lccs, sort_lcc_index):
assert d.lcc == set()
assert d.lcc_sort is None

DDC_TESTS = {
DDC_TESTS: ClassVar[dict[str, tuple[list[str], list[str] | None, int | None]]] = {
'Remove dupes': (['123.5', '123.5'], ['123.5'], 0),
'Handles none': ([], None, None),
'Handles empty string': ([''], None, None),
Expand Down
6 changes: 3 additions & 3 deletions scripts/partner_batch_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import re
from collections.abc import Mapping
from typing import cast
from typing import ClassVar, cast

import requests

Expand Down Expand Up @@ -84,7 +84,7 @@


class Biblio:
ACTIVE_FIELDS = [
ACTIVE_FIELDS: ClassVar[list[str]] = [
'title',
'isbn_13',
'publish_date',
Expand All @@ -101,7 +101,7 @@ class Biblio:
'identifiers',
'dewey_decimal_class',
]
INACTIVE_FIELDS = [
INACTIVE_FIELDS: ClassVar[list[str]] = [
"copyright",
"length",
"width",
Expand Down
6 changes: 3 additions & 3 deletions scripts/providers/isbndb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
from json import JSONDecodeError
from typing import Any, Final
from typing import Any, ClassVar, Final

import requests

Expand Down Expand Up @@ -34,7 +34,7 @@ def is_nonbook(binding: str, nonbooks: list[str]) -> bool:


class ISBNdb:
ACTIVE_FIELDS = [
ACTIVE_FIELDS: ClassVar[list[str]] = [
'authors',
'isbn_13',
'languages',
Expand All @@ -45,7 +45,7 @@ class ISBNdb:
'subjects',
'title',
]
INACTIVE_FIELDS = [
INACTIVE_FIELDS: ClassVar[list[str]] = [
"copyright",
"dewey",
"doi",
Expand Down
Loading