Skip to content

Commit

Permalink
pylint: enable useless-suppression lint and perform cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Jul 27, 2024
1 parent 81ee5e9 commit 0b87aac
Show file tree
Hide file tree
Showing 65 changed files with 31 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ disable =
too-many-instance-attributes,
unnecessary-lambda-assignment,
unsubscriptable-object,
enable =
useless-suppression

[FORMAT]
max-line-length=88
1 change: 0 additions & 1 deletion bookwyrm/activitypub/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Edition(Book):
type: str = "Edition"


# pylint: disable=invalid-name
@dataclass(init=False)
class Work(Book):
"""work instance of a book object"""
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/activitypub/ordered_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class OrderedCollection(ActivityObject):
type: str = "OrderedCollection"


# pylint: disable=invalid-name
@dataclass(init=False)
class OrderedCollectionPrivate(OrderedCollection):
"""an ordered collection with privacy settings"""
Expand Down
4 changes: 0 additions & 4 deletions bookwyrm/activitypub/verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def action(self, allow_external_connections=True):
self.object.to_model(allow_external_connections=allow_external_connections)


# pylint: disable=invalid-name
@dataclass(init=False)
class Create(Verb):
"""Create activity"""
Expand All @@ -33,7 +32,6 @@ class Create(Verb):
type: str = "Create"


# pylint: disable=invalid-name
@dataclass(init=False)
class Delete(Verb):
"""Create activity"""
Expand Down Expand Up @@ -63,7 +61,6 @@ def action(self, allow_external_connections=True):
# if we can't find it, we don't need to delete it because we don't have it


# pylint: disable=invalid-name
@dataclass(init=False)
class Update(Verb):
"""Update activity"""
Expand Down Expand Up @@ -227,7 +224,6 @@ def action(self, allow_external_connections=True):
self.to_model(allow_external_connections=allow_external_connections)


# pylint: disable=invalid-name
@dataclass(init=False)
class Announce(Verb):
"""boosting a status"""
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/activitystreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def unread_by_status_type_id(self, user_id):
stream_id = self.stream_id(user_id)
return f"{stream_id}-unread-by-type"

def get_rank(self, obj): # pylint: disable=no-self-use
def get_rank(self, obj):
"""statuses are sorted by date published"""
return obj.published_date.timestamp()

Expand Down
1 change: 0 additions & 1 deletion bookwyrm/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class BookwyrmConfig(AppConfig):
name = "bookwyrm"
verbose_name = "BookWyrm"

# pylint: disable=no-self-use
def ready(self):
"""set up OTLP and preview image files, if desired"""
if settings.OTEL_EXPORTER_OTLP_ENDPOINT or settings.OTEL_EXPORTER_CONSOLE:
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/book_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def search(
...


# pylint: disable=arguments-differ
def search(
query: str,
*,
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bookwyrm import models, settings


def site_settings(request): # pylint: disable=unused-argument
def site_settings(request):
"""include the custom info about the site"""
request_protocol = "https://"
if not request.is_secure():
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/forms/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def __init__(self, *args, **kwargs):
css_classes["number"] = "input"
css_classes["checkbox"] = "checkbox"
css_classes["textarea"] = "textarea"
# pylint: disable=super-with-arguments
super().__init__(*args, **kwargs)
for visible in self.visible_fields():
input_type = ""
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/forms/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def infer_username(self):

def add_invalid_password_error(self):
"""We don't want to be too specific about this"""
# pylint: disable=attribute-defined-outside-init
self.non_field_errors = _("Username or password are incorrect")


Expand Down
2 changes: 0 additions & 2 deletions bookwyrm/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
class ArrayWidget(forms.widgets.TextInput):
"""Inputs for postgres array fields"""

# pylint: disable=unused-argument
# pylint: disable=no-self-use
def value_from_datadict(self, data, files, name):
"""get all values for this name"""
return [i for i in data.getlist(name) if i]
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/importers/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Importer:
"reading": ["currently-reading", "reading", "currently reading"],
}

# pylint: disable=too-many-locals
def create_job(
self, user: User, csv_file: Iterable[str], include_reviews: bool, privacy: str
) -> ImportJob:
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/importers/librarything_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LibrarythingImporter(Importer):

def normalize_row(
self, entry: dict[str, str], mappings: dict[str, Optional[str]]
) -> dict[str, Optional[str]]: # pylint: disable=no-self-use
) -> dict[str, Optional[str]]:
"""use the dataclass to create the formatted row of data"""
normalized = {
k: _remove_brackets(entry.get(v) if v else None)
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/lists_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def stream_id(self, user): # pylint: disable=no-self-use
return f"{user}-lists"
return f"{user.id}-lists"

def get_rank(self, obj): # pylint: disable=no-self-use
def get_rank(self, obj):
"""lists are sorted by updated date"""
return obj.updated_date.timestamp()

Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/models/activitypub_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

PropertyField = namedtuple("PropertyField", ("set_activity_from_field"))

# pylint: disable=invalid-name

def set_activity_from_property_field(activity, obj, field):
"""assign a model property value to the activity json"""
activity[field[1]] = getattr(obj, field[0])
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/models/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def merge_into(self, canonical: Self, dry_run=False) -> Dict[str, Any]:
related_models = [
(r.remote_field.name, r.related_model) for r in self._meta.related_objects
]
# pylint: disable=protected-access
for related_field, related_model in related_models:
# Skip the ManyToMany fields that aren’t auto-created. These
# should have a corresponding OneToMany field in the model for
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/models/bookwyrm_export_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class BookwyrmAwsSession(BotoSession):
"""a boto session that always uses settings.AWS_S3_ENDPOINT_URL"""

def client(self, *args, **kwargs): # pylint: disable=arguments-differ
def client(self, *args, **kwargs):
kwargs["endpoint_url"] = settings.AWS_S3_ENDPOINT_URL
return super().client("s3", *args, **kwargs)

Expand Down
7 changes: 2 additions & 5 deletions bookwyrm/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ class UsernameField(ActivitypubFieldMixin, models.CharField):

def __init__(self, activitypub_field="preferredUsername", **kwargs):
self.activitypub_field = activitypub_field
# I don't totally know why pylint is mad at this, but it makes it work
super(ActivitypubFieldMixin, self).__init__( # pylint: disable=bad-super-call
super(ActivitypubFieldMixin, self).__init__(
_("username"),
max_length=150,
unique=True,
Expand Down Expand Up @@ -234,7 +233,6 @@ class PrivacyField(ActivitypubFieldMixin, models.CharField):
def __init__(self, *args, **kwargs):
super().__init__(*args, max_length=255, choices=PrivacyLevels, default="public")

# pylint: disable=invalid-name
def set_field_from_activity(
self, instance, data, overwrite=True, allow_external_connections=True
):
Expand Down Expand Up @@ -276,7 +274,6 @@ def set_activity_from_field(self, activity, instance):
if hasattr(instance, "mention_users"):
mentions = [u.remote_id for u in instance.mention_users.all()]
# this is a link to the followers list
# pylint: disable=protected-access
followers = instance.user.followers_url
if instance.privacy == "public":
activity["to"] = [self.public]
Expand Down Expand Up @@ -444,7 +441,7 @@ def __init__(self, *args, alt_field=None, **kwargs):
self.alt_field = alt_field
super().__init__(*args, **kwargs)

# pylint: disable=arguments-differ,arguments-renamed,too-many-arguments
# pylint: disable=arguments-renamed,too-many-arguments
def set_field_from_activity(
self, instance, data, save=True, overwrite=True, allow_external_connections=True
):
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/models/import_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def import_item_task(item_id):

try:
item.resolve()
except Exception as err: # pylint: disable=broad-except
except Exception as err:
item.fail_reason = _("Error loading book")
item.save()
item.update_job()
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/models/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
status = "follow_request"
activity_serializer = activitypub.Follow

def save(self, *args, broadcast=True, **kwargs): # pylint: disable=arguments-differ
def save(self, *args, broadcast=True, **kwargs):
"""make sure the follow or block relationship doesn't already exist"""
# if there's a request for a follow that already exists, accept it
# without changing the local database state
Expand Down
4 changes: 2 additions & 2 deletions bookwyrm/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def save(self, *args, update_fields: Optional[Iterable[str]] = None, **kwargs):
self.thread_id = self.id
super().save(broadcast=False, update_fields=["thread_id"])

def delete(self, *args, **kwargs): # pylint: disable=unused-argument
def delete(self, *args, **kwargs):
""" "delete" a status"""
if hasattr(self, "boosted_status"):
# okay but if it's a boost really delete it
Expand Down Expand Up @@ -213,7 +213,7 @@ def to_replies(self, **kwargs):
**kwargs,
).serialize()

def to_activity_dataclass(self, pure=False): # pylint: disable=arguments-differ
def to_activity_dataclass(self, pure=False):
"""return tombstone if the status is deleted"""
if self.deleted:
return activitypub.Tombstone(
Expand Down
3 changes: 0 additions & 3 deletions bookwyrm/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def save(self, *args, update_fields: Optional[Iterable[str]] = None, **kwargs):

def delete(self, *args, **kwargs):
"""We don't actually delete the database entry"""
# pylint: disable=attribute-defined-outside-init
self.is_active = False
self.allow_reactivation = False
self.is_deleted = True
Expand Down Expand Up @@ -452,15 +451,13 @@ def erase_user_statuses(self, broadcast=True):

def deactivate(self):
"""Disable the user but allow them to reactivate"""
# pylint: disable=attribute-defined-outside-init
self.is_active = False
self.deactivation_reason = "self_deactivation"
self.allow_reactivation = True
super().save(broadcast=False)

def reactivate(self):
"""Now you want to come back, huh?"""
# pylint: disable=attribute-defined-outside-init
if not self.allow_reactivation:
return
self.is_active = True
Expand Down
2 changes: 0 additions & 2 deletions bookwyrm/preview_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def save_and_cleanup(image, instance=None):
return True


# pylint: disable=invalid-name
@app.task(queue=IMAGES)
def generate_site_preview_image_task():
"""generate preview_image for the website"""
Expand All @@ -445,7 +444,6 @@ def generate_site_preview_image_task():
save_and_cleanup(image, instance=site)


# pylint: disable=invalid-name
@app.task(queue=IMAGES)
def generate_edition_preview_image_task(book_id):
"""generate preview_image for a book"""
Expand Down
3 changes: 1 addition & 2 deletions bookwyrm/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from Crypto import Random
from Crypto.PublicKey import RSA
from Crypto.Signature import pkcs1_15 # pylint: disable=no-name-in-module
from Crypto.Signature import pkcs1_15
from Crypto.Hash import SHA256

MAX_SIGNATURE_AGE = 300
Expand Down Expand Up @@ -84,7 +84,6 @@ def __init__(self, key_id, headers, signature):
self.headers = headers
self.signature = signature

# pylint: disable=invalid-name
@classmethod
def parse(cls, request):
"""extract and parse a signature from an http request"""
Expand Down
4 changes: 1 addition & 3 deletions bookwyrm/suggested_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def store_id(self, user): # pylint: disable=no-self-use

def get_counts_from_rank(self, rank): # pylint: disable=no-self-use
"""calculate mutuals count and shared books count from rank"""
# pylint: disable=c-extension-no-member
return {
"mutuals": math.floor(rank),
# "shared_books": int(1 / (-1 * (rank % 1 - 1))) - 1,
Expand Down Expand Up @@ -128,7 +127,6 @@ def get_annotated_users(viewer, *args, **kwargs):
),
distinct=True,
),
# pylint: disable=line-too-long
# shared_books=Count(
# "shelfbook",
# filter=Q(
Expand Down Expand Up @@ -202,7 +200,7 @@ def update_suggestions_on_unfollow(sender, instance, **kwargs):


@receiver(signals.post_save, sender=models.User)
# pylint: disable=unused-argument, too-many-arguments
# pylint: disable=unused-argument
def update_user(sender, instance, created, update_fields=None, **kwargs):
"""an updated user, neat"""
# a new user is found, create suggestions for them
Expand Down
2 changes: 0 additions & 2 deletions bookwyrm/tests/connectors/test_abstract_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_get_or_create_book_deduped(self):
@responses.activate
def test_get_or_create_author(self):
"""load an author"""
# pylint: disable=attribute-defined-outside-init
self.connector.author_mappings = [
Mapping("id"),
Mapping("name"),
Expand All @@ -141,7 +140,6 @@ def test_get_or_create_author_existing(self):
def test_update_author_from_remote(self):
"""trigger the function that looks up the remote data"""
author = models.Author.objects.create(name="Test", openlibrary_key="OL123A")
# pylint: disable=attribute-defined-outside-init
self.connector.author_mappings = [
Mapping("id"),
Mapping("name"),
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/tests/models/test_activitypub_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from bookwyrm.settings import PAGE_LENGTH


# pylint: disable=invalid-name,too-many-public-methods
# pylint: disable=too-many-public-methods
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class ActivitypubMixins(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/tests/models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BookWyrmTestModel(base_model.BookWyrmModel):

def test_remote_id(self):
"""these should be generated"""
self.test_model.id = 1 # pylint: disable=invalid-name
self.test_model.id = 1
expected = self.test_model.get_remote_id()
self.assertEqual(expected, f"{BASE_URL}/bookwyrmtestmodel/1")

Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/tests/models/test_bookwyrm_import_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bookwyrm.models import bookwyrm_import_job


class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
class BookwyrmImport(TestCase):
"""testing user import functions"""

def setUp(self):
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/tests/models/test_shelf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from bookwyrm import models, settings


# pylint: disable=unused-argument
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MergeBookDataModel(TestCase):
"""test merging of subclasses of BookDataModel"""

@classmethod
def setUpTestData(cls): # pylint: disable=invalid-name
def setUpTestData(cls):
"""shared data"""
models.SiteSettings.objects.create()

Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/tests/validate_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def validate_html(html):
validator.feed(str(html.content))


class HtmlValidator(HTMLParser): # pylint: disable=abstract-method
class HtmlValidator(HTMLParser):
"""Checks for custom html validation requirements"""

def __init__(self):
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/tests/views/imports/test_user_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
class ImportUserViews(TestCase):
"""user import views"""

# pylint: disable=invalid-name
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()
Expand Down
Loading

0 comments on commit 0b87aac

Please sign in to comment.