Refactor and enhance type hints across multiple modules
- Updated the `from_tuple` method in `Prof` class to specify return type. - Added type hints for various methods in `LehmannsClient`, `OpenAI`, `WebRequest`, and `ZoteroController` classes to improve code clarity and type safety. - Modified `pdf_to_csv` function to return a string instead of a DataFrame. - Enhanced error handling and type hints in `wordparser` and `xmlparser` modules. - Removed unused UI file `Ui_medianadder.ts`. - Improved the layout and structure of the `semesterapparat_ui` to enhance user experience. - Updated file picker to support `.doc` files in addition to `.docx`. - Added unique item handling in `Ui` class to prevent duplicates in apparat list. - General code cleanup and consistency improvements across various files.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
def create_blob(file: str):
|
||||
def create_blob(file: str) -> bytes:
|
||||
"""
|
||||
Creates a blob from a file.
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import os
|
||||
from pyramid.config import Configurator
|
||||
from wsgiref.simple_server import WSGIRequestHandler
|
||||
from src import LOG_DIR
|
||||
import logging
|
||||
import os
|
||||
from wsgiref.simple_server import WSGIRequestHandler
|
||||
|
||||
from pyramid.config import Configurator
|
||||
|
||||
from src import LOG_DIR
|
||||
|
||||
log_path = os.path.join(LOG_DIR, "web_documentation.log")
|
||||
|
||||
@@ -31,7 +32,7 @@ class QuietHandler(WSGIRequestHandler):
|
||||
pass
|
||||
|
||||
|
||||
def website():
|
||||
def website() -> object:
|
||||
config = Configurator()
|
||||
|
||||
# Set up static file serving from the 'site/' directory
|
||||
@@ -40,4 +41,4 @@ def website():
|
||||
)
|
||||
|
||||
app = config.make_wsgi_app()
|
||||
return app
|
||||
return app # type: ignore
|
||||
|
||||
@@ -2,9 +2,9 @@ import pickle
|
||||
from typing import Any
|
||||
|
||||
|
||||
def load_pickle(data: Any):
|
||||
def load_pickle(data: Any) -> Any:
|
||||
return pickle.loads(data)
|
||||
|
||||
|
||||
def dump_pickle(data: Any):
|
||||
def dump_pickle(data: Any) -> bytes:
|
||||
return pickle.dumps(data)
|
||||
|
||||
@@ -16,7 +16,7 @@ logger = log
|
||||
font = "Cascadia Mono"
|
||||
|
||||
|
||||
def print_document(file: str):
|
||||
def print_document(file: str) -> None:
|
||||
# send document to printer as attachment of email
|
||||
import smtplib
|
||||
from email.mime.application import MIMEApplication
|
||||
@@ -98,7 +98,7 @@ class SemesterDocument:
|
||||
self.filename = filename
|
||||
if full:
|
||||
log.info("Full document generation")
|
||||
self.cleanup()
|
||||
self.cleanup
|
||||
log.info("Cleanup done")
|
||||
self.make_document()
|
||||
log.info("Document created")
|
||||
@@ -221,15 +221,15 @@ class SemesterDocument:
|
||||
|
||||
self.create_sorted_table()
|
||||
|
||||
def save_document(self, name):
|
||||
def save_document(self, name: str) -> None:
|
||||
# Save the document
|
||||
self.doc.save(name)
|
||||
|
||||
def create_pdf(self):
|
||||
def create_pdf(self) -> None:
|
||||
# Save the document
|
||||
import comtypes.client
|
||||
|
||||
word = comtypes.client.CreateObject("Word.Application")
|
||||
word = comtypes.client.CreateObject("Word.Application") # type: ignore
|
||||
self.save_document(self.filename + ".docx")
|
||||
docpath = os.path.abspath(self.filename + ".docx")
|
||||
doc = word.Documents.Open(docpath)
|
||||
@@ -240,13 +240,13 @@ class SemesterDocument:
|
||||
log.debug("PDF saved")
|
||||
|
||||
@property
|
||||
def cleanup(self):
|
||||
def cleanup(self) -> None:
|
||||
if os.path.exists(f"{self.filename}.docx"):
|
||||
os.remove(f"{self.filename}.docx")
|
||||
os.remove(f"{self.filename}.pdf")
|
||||
|
||||
@property
|
||||
def send(self):
|
||||
def send(self) -> None:
|
||||
print_document(self.filename + ".pdf")
|
||||
log.debug("Document sent to printer")
|
||||
|
||||
@@ -309,11 +309,11 @@ class SemapSchilder:
|
||||
self.doc.save(f"{self.filename}.docx")
|
||||
log.debug(f"Document saved as {self.filename}.docx")
|
||||
|
||||
def create_pdf(self):
|
||||
def create_pdf(self) -> None:
|
||||
# Save the document
|
||||
import comtypes.client
|
||||
|
||||
word = comtypes.client.CreateObject("Word.Application")
|
||||
word = comtypes.client.CreateObject("Word.Application") # type: ignore
|
||||
self.save_document()
|
||||
docpath = os.path.abspath(f"{self.filename}.docx")
|
||||
doc = word.Documents.Open(docpath)
|
||||
@@ -323,14 +323,14 @@ class SemapSchilder:
|
||||
word.Quit()
|
||||
log.debug("PDF saved")
|
||||
|
||||
def cleanup(self):
|
||||
def cleanup(self) -> None:
|
||||
if os.path.exists(f"{self.filename}.docx"):
|
||||
os.remove(f"{self.filename}.docx")
|
||||
if os.path.exists(f"{self.filename}.pdf"):
|
||||
os.remove(f"{self.filename}.pdf")
|
||||
|
||||
@property
|
||||
def send(self):
|
||||
def send(self) -> None:
|
||||
print_document(self.filename + ".pdf")
|
||||
log.debug("Document sent to printer")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user