From 70f3f983630922e55e57c7327f72dad21d3f716b Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Tue, 13 Jun 2023 10:55:52 -0700 Subject: [PATCH] Let ruff autofix some things from the newest version --- docker/wait-for-redis.py | 2 +- src/documents/barcodes.py | 6 +++--- src/documents/signals/handlers.py | 6 +++--- src/documents/tasks.py | 2 +- src/documents/views.py | 8 ++++---- src/paperless_mail/mail.py | 2 +- src/paperless_tesseract/parsers.py | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docker/wait-for-redis.py b/docker/wait-for-redis.py index d6ce5c639..41df5a08b 100755 --- a/docker/wait-for-redis.py +++ b/docker/wait-for-redis.py @@ -28,7 +28,7 @@ if __name__ == "__main__": except Exception as e: print( f"Redis ping #{attempt} failed.\n" - f"Error: {str(e)}.\n" + f"Error: {e!s}.\n" f"Waiting {RETRY_SLEEP_SECONDS}s", flush=True, ) diff --git a/src/documents/barcodes.py b/src/documents/barcodes.py index dfeac545b..f3d59bc5b 100644 --- a/src/documents/barcodes.py +++ b/src/documents/barcodes.py @@ -121,7 +121,7 @@ class BarcodeReader: if barcode.text: barcodes.append(barcode.text) logger.debug( - f"Barcode of type {str(barcode.format)} found: {barcode.text}", + f"Barcode of type {barcode.format} found: {barcode.text}", ) return barcodes @@ -141,7 +141,7 @@ class BarcodeReader: decoded_barcode = barcode.data.decode("utf-8") barcodes.append(decoded_barcode) logger.debug( - f"Barcode of type {str(barcode.type)} found: {decoded_barcode}", + f"Barcode of type {barcode.type} found: {decoded_barcode}", ) return barcodes @@ -348,7 +348,7 @@ class BarcodeReader: for idx, document_path in enumerate(doc_paths): if override_name is not None: - newname = f"{str(idx)}_{override_name}" + newname = f"{idx}_{override_name}" dest = save_to_dir / newname else: dest = save_to_dir diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 40765443b..4a39d98ea 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -346,7 +346,7 @@ def cleanup_document_deletion(sender, instance, using, **kwargs): logger.debug(f"Deleted file {filename}.") except OSError as e: logger.warning( - f"While deleting document {str(instance)}, the file " + f"While deleting document {instance!s}, the file " f"{filename} could not be deleted: {e}", ) @@ -369,13 +369,13 @@ class CannotMoveFilesException(Exception): def validate_move(instance, old_path, new_path): if not os.path.isfile(old_path): # Can't do anything if the old file does not exist anymore. - logger.fatal(f"Document {str(instance)}: File {old_path} has gone.") + logger.fatal(f"Document {instance!s}: File {old_path} has gone.") raise CannotMoveFilesException if os.path.isfile(new_path): # Can't do anything if the new file already exists. Skip updating file. logger.warning( - f"Document {str(instance)}: Cannot rename file " + f"Document {instance!s}: Cannot rename file " f"since target path {new_path} already exists.", ) raise CannotMoveFilesException diff --git a/src/documents/tasks.py b/src/documents/tasks.py index 1603a1359..d320875a0 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -116,7 +116,7 @@ def consume_file( {"type": "status_update", "data": payload}, ) except ConnectionError as e: - logger.warning(f"ConnectionError on status send: {str(e)}") + logger.warning(f"ConnectionError on status send: {e!s}") # consuming stops here, since the original document with # the barcodes has been split and will be consumed separately diff --git a/src/documents/views.py b/src/documents/views.py index d60cf459d..cd69095fe 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -519,7 +519,7 @@ class DocumentViewSet( try: return Response(self.getNotes(doc)) except Exception as e: - logger.warning(f"An error occurred retrieving notes: {str(e)}") + logger.warning(f"An error occurred retrieving notes: {e!s}") return Response( {"error": "Error retreiving notes, check logs for more detail."}, ) @@ -538,7 +538,7 @@ class DocumentViewSet( return Response(self.getNotes(doc)) except Exception as e: - logger.warning(f"An error occurred saving note: {str(e)}") + logger.warning(f"An error occurred saving note: {e!s}") return Response( { "error": "Error saving note, check logs for more detail.", @@ -628,7 +628,7 @@ class UnifiedSearchViewSet(DocumentViewSet): except NotFound: raise except Exception as e: - logger.warning(f"An error occurred listing search results: {str(e)}") + logger.warning(f"An error occurred listing search results: {e!s}") return HttpResponseBadRequest( "Error listing search results, check logs for more detail.", ) @@ -699,7 +699,7 @@ class BulkEditView(GenericAPIView): result = method(documents, **parameters) return Response({"result": result}) except Exception as e: - logger.warning(f"An error occurred performing bulk edit: {str(e)}") + logger.warning(f"An error occurred performing bulk edit: {e!s}") return HttpResponseBadRequest( "Error performing bulk edit, check logs for more detail.", ) diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index bfb306e5a..65768d3c2 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -544,7 +544,7 @@ class MailAccountHandler(LoggingMixin): criterias = make_criterias(rule, supports_gmail_labels) self.log.debug( - f"Rule {rule}: Searching folder with criteria {str(criterias)}", + f"Rule {rule}: Searching folder with criteria {criterias}", ) try: diff --git a/src/paperless_tesseract/parsers.py b/src/paperless_tesseract/parsers.py index b6a721b2f..c6d066fbe 100644 --- a/src/paperless_tesseract/parsers.py +++ b/src/paperless_tesseract/parsers.py @@ -335,7 +335,7 @@ class RasterisedDocumentParser(DocumentParser): self.text = text_original except (NoTextFoundException, InputFileError) as e: self.log.warning( - f"Encountered an error while running OCR: {str(e)}. " + f"Encountered an error while running OCR: {e!s}. " f"Attempting force OCR to get the text.", ) @@ -370,11 +370,11 @@ class RasterisedDocumentParser(DocumentParser): except Exception as e: # If this fails, we have a serious issue at hand. - raise ParseError(f"{e.__class__.__name__}: {str(e)}") from e + raise ParseError(f"{e.__class__.__name__}: {e!s}") from e except Exception as e: # Anything else is probably serious. - raise ParseError(f"{e.__class__.__name__}: {str(e)}") from e + raise ParseError(f"{e.__class__.__name__}: {e!s}") from e # As a last resort, if we still don't have any text for any reason, # try to extract the text from the original document.