Skip to content

Commit

Permalink
Fix mypy typing issues
Browse files Browse the repository at this point in the history
Numpy 2.0 released and can cause some potential issues, so restrict to
1.x.y for now.

* `docx.Document` is a constructor function, `docx.document.Document` is
  the type itself
* Some unused weirdness in `get_possible_radios` popped up: the function
  is untested, so I fixed the typing issues
  • Loading branch information
BryceStevenWilley committed Jun 17, 2024
1 parent fce8447 commit 79bd7a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions formfyxer/docx_wrangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def add_run_after(run, text):


def update_docx(
document: Union[docx.Document, str], modified_runs: List[Tuple[int, int, str, int]]
) -> docx.Document:
document: Union[docx.document.Document, str], modified_runs: List[Tuple[int, int, str, int]]
) -> docx.document.Document:
"""Update the document with the modified runs.
Note: OpenAI is probabilistic, so the modified run indices may not be correct.
Expand Down Expand Up @@ -416,7 +416,7 @@ def get_modified_docx_runs(
guesses = json.loads(response.choices[0].message.content)["results"]
return guesses

def make_docx_plain_language(docx_path: str) -> docx.Document:
def make_docx_plain_language(docx_path: str) -> docx.document.Document:
"""
Convert a DOCX file to plain language with the help of OpenAI.
"""
Expand All @@ -443,7 +443,7 @@ def make_docx_plain_language(docx_path: str) -> docx.Document:
)
return update_docx(docx.Document(docx_path), guesses)

def modify_docx_with_openai_guesses(docx_path: str) -> docx.Document:
def modify_docx_with_openai_guesses(docx_path: str) -> docx.document.Document:
"""Uses OpenAI to guess the variable names for a document and then modifies the document with the guesses.
Args:
Expand Down
4 changes: 2 additions & 2 deletions formfyxer/pdf_wrangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
maxRadius=50,
)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
rounded_circles = np.around(circles)
for i in rounded_circles[0, :]:
center = (i[0], i[1])
# circle center
cv2.circle(img_mat, center, 1, (0, 100, 100), 3)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run(self):
license='MIT',
packages=['formfyxer'],
install_requires=['spacy', 'pdfminer.six', 'pandas', 'pikepdf',
'textstat', 'requests', 'numpy', 'scikit-learn==1.2.2', 'networkx', 'joblib',
'textstat', 'requests', 'numpy<2.0.0', 'scikit-learn==1.2.2', 'networkx', 'joblib',
'nltk', 'boxdetect', 'pdf2image', 'reportlab>=3.6.13', 'pdfminer.six',
'opencv-python', 'ocrmypdf', 'eyecite', 'passivepy>=0.2.16', 'sigfig',
'typer>=0.4.1,<0.5.0', # typer pre 0.4.1 was broken by click 8.1.0: https://github.com/explosion/spaCy/issues/10564
Expand Down

0 comments on commit 79bd7a9

Please sign in to comment.