diff --git a/ruff.toml b/ruff.toml index 656ca04..36efea0 100644 --- a/ruff.toml +++ b/ruff.toml @@ -27,12 +27,9 @@ lint.extend-ignore = [ "E712", # ... "E713", # Test for membership should be `not in` "PLR2044", # Line with empty comment - "RUF027", # Possible f-string without an `f` prefix "S101", # Use of `assert` detected "S320", # OK, we're using defusedxml -# "TCH001", # Move import into a type-checking block -# "TCH002", # Move import into a type-checking block -# "TCH003", # Move import into a type-checking block + "ISC001", # Conflicts with formatter # Fix these (if possible / reasonable) "A001", # Variable `...` is shadowing a python builtin @@ -101,6 +98,7 @@ lint.extend-ignore = [ "RET505", # Unnecessary `else` after `return` statement "RUF005", # Consider iterable unpacking instead of concatenation "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + # "S104", # Possible binding to all interfaces "S301", # `pickle`... "S403", # `pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure @@ -111,13 +109,13 @@ lint.extend-ignore = [ "S606", # Subprocess related... "S607", # Subprocess related... "S701", # By default, jinja2 sets `autoescape` to `False`. + # "SIM102", # Use a single `if` statement instead of nested `if` statements "SIM108", # Use ternary operator "SIM115", # Use context handler for opening files "SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements "SLF001", # Private member accessed "T201", # `print` found - "UP032", # Use f-strings ] [lint.mccabe] diff --git a/setup.cfg b/setup.cfg index 6f3308d..7fc9c05 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,8 @@ ignore = F841 # ambiguous variable name E741 + # Line too long + E501 # abstract base class, but it has no abstract methods B024 # something something abstract class diff --git a/src/abilian/core/models/attachment.py b/src/abilian/core/models/attachment.py index b5c0c09..acbc94b 100644 --- a/src/abilian/core/models/attachment.py +++ b/src/abilian/core/models/attachment.py @@ -102,9 +102,7 @@ def __repr__(self) -> str: class_ = self.__class__ mod_ = class_.__module__ classname = class_.__name__ - return "<{}.{} instance at 0x{:x} entity id={!r}>".format( - mod_, classname, id(self), self.entity_id - ) + return f"<{mod_}.{classname} instance at 0x{id(self):x} entity id={self.entity_id!r}>" @sa.event.listens_for(Attachment, "before_insert", propagate=True) diff --git a/src/abilian/core/models/subjects.py b/src/abilian/core/models/subjects.py index 4c1e182..8dc56f8 100644 --- a/src/abilian/core/models/subjects.py +++ b/src/abilian/core/models/subjects.py @@ -293,13 +293,7 @@ def __str__(self) -> str: def __repr__(self) -> str: cls = self.__class__ - return "<{mod}.{cls} id={id!r} email={email!r} at 0x{addr:x}>".format( - mod=cls.__module__, - cls=cls.__name__, - id=self.id, - email=self.email, - addr=id(self), - ) + return f"<{cls.__module__}.{cls.__name__} id={self.id!r} email={self.email!r} at 0x{id(self):x}>" @listens_for(User, "mapper_configured", propagate=True) diff --git a/src/abilian/sbe/apps/documents/models.py b/src/abilian/sbe/apps/documents/models.py index e02693f..6e2e59f 100644 --- a/src/abilian/sbe/apps/documents/models.py +++ b/src/abilian/sbe/apps/documents/models.py @@ -670,9 +670,7 @@ def file_name(self) -> str: return self.title def __repr__(self) -> str: - return "".format( - self.id, self.title, self.path, self.content_length, id(self) - ) + return f"" # locking management; used for checkin/checkout - this could be generalized to # any entity diff --git a/src/abilian/sbe/apps/documents/views/documents.py b/src/abilian/sbe/apps/documents/views/documents.py index ac2d171..80abc04 100644 --- a/src/abilian/sbe/apps/documents/views/documents.py +++ b/src/abilian/sbe/apps/documents/views/documents.py @@ -198,8 +198,8 @@ def document_download(doc_id: int, attach: bool = False) -> Response: ): # Note: we omit text/html for security reasons. quoted_filename = quote(doc.title.encode("utf8")) - response.headers["content-disposition"] = 'attachment;filename="{}"'.format( - quoted_filename + response.headers["content-disposition"] = ( + f'attachment;filename="{quoted_filename}"' ) return response diff --git a/src/abilian/sbe/apps/social/views/users.py b/src/abilian/sbe/apps/social/views/users.py index ec2b2fd..3e9cf25 100644 --- a/src/abilian/sbe/apps/social/views/users.py +++ b/src/abilian/sbe/apps/social/views/users.py @@ -123,8 +123,8 @@ def users_dt_json(): name = escape(user.name or "") cell0 = ( - '' - "".format(url=user_url, src=mugshot, size=MUGSHOT_SIZE) + f'' + "" ) cell1 = f'' cell2 = age(user.created_at) diff --git a/src/abilian/services/audit/service.py b/src/abilian/services/audit/service.py index 965f1a0..385e44c 100644 --- a/src/abilian/services/audit/service.py +++ b/src/abilian/services/audit/service.py @@ -174,11 +174,9 @@ def setup_auditable_entity(self, entity_class: Any): backref_attr = ".".join(inferred_backref) else: raise ValueError( - "Audit setup class<{cls}: Could not guess backref name" - ' of relationship "{related_attr}", please use tuple annotation ' - "on __auditable_entity__".format( - cls=entity_class.__name__, related_attr=related_attr - ) + f"Audit setup class<{entity_class.__name__}: Could not guess backref name" + f' of relationship "{related_attr}", please use tuple annotation ' + "on __auditable_entity__" ) meta.related = related_path diff --git a/src/abilian/web/action.py b/src/abilian/web/action.py index 65c2a15..01787f2 100644 --- a/src/abilian/web/action.py +++ b/src/abilian/web/action.py @@ -236,12 +236,7 @@ def __str__(self) -> str: return str(url_for(self.name, **self.get_kwargs())) def __repr__(self) -> str: - return "{cls}({name!r}, *{args!r}, **{kwargs!r})".format( - cls=self.__class__.__name__, - name=self.name, - args=self.args, - kwargs=self.kwargs, - ) + return f"{self.__class__.__name__}({self.name!r}, *{self.args!r}, **{self.kwargs!r})" class Action: diff --git a/src/abilian/web/admin/panels/users/views.py b/src/abilian/web/admin/panels/users/views.py index e114362..446bcd9 100644 --- a/src/abilian/web/admin/panels/users/views.py +++ b/src/abilian/web/admin/panels/users/views.py @@ -89,9 +89,7 @@ def data(self, *args, **kw) -> dict: r for r in security.get_roles(user, no_group_roles=True) if r.assignable ] columns = [ - ''.format( - url=user_url, src=mugshot, size=MUGSHOT_SIZE - ), + f'', f'{name}', f'{email}', "\u2713" if user.can_login else "", diff --git a/src/abilian/web/forms/form.py b/src/abilian/web/forms/form.py index 975ee9b..78b1560 100644 --- a/src/abilian/web/forms/form.py +++ b/src/abilian/web/forms/form.py @@ -204,9 +204,7 @@ def _core_field_repr(self) -> str: Useful for tracing field errors (like in Sentry). """ - return "<{}.{} at 0x{:x} name={!r}>".format( - self.__class__.__module__, self.__class__.__name__, id(self), self.name - ) + return f"<{self.__class__.__module__}.{self.__class__.__name__} at 0x{id(self):x} name={self.name!r}>" patch_logger.info(f"{Field.__module__}.Field.__repr__") Field.__repr__ = _core_field_repr