From cdfd67d1aac442e5b226ec6090cb19061b8920c6 Mon Sep 17 00:00:00 2001 From: John <43506685+Coniferish@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:55:39 -0400 Subject: [PATCH 1/5] add annotations import to human-written code --- _test_unstructured_client/integration/test_decorators.py | 2 ++ _test_unstructured_client/unit/test_split_pdf_hook.py | 2 ++ src/unstructured_client/_hooks/custom/clean_server_url_hook.py | 2 ++ src/unstructured_client/_hooks/custom/logger_hook.py | 2 ++ src/unstructured_client/_hooks/custom/pdf_utils.py | 2 ++ src/unstructured_client/_hooks/custom/suggest_defining_url.py | 2 ++ 6 files changed, 12 insertions(+) diff --git a/_test_unstructured_client/integration/test_decorators.py b/_test_unstructured_client/integration/test_decorators.py index 4fc396d0..b80185f2 100644 --- a/_test_unstructured_client/integration/test_decorators.py +++ b/_test_unstructured_client/integration/test_decorators.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import httpx import json import pytest diff --git a/_test_unstructured_client/unit/test_split_pdf_hook.py b/_test_unstructured_client/unit/test_split_pdf_hook.py index fa3dfc4b..d09c894e 100644 --- a/_test_unstructured_client/unit/test_split_pdf_hook.py +++ b/_test_unstructured_client/unit/test_split_pdf_hook.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import asyncio import io import logging diff --git a/src/unstructured_client/_hooks/custom/clean_server_url_hook.py b/src/unstructured_client/_hooks/custom/clean_server_url_hook.py index ca893660..5fcf4a96 100644 --- a/src/unstructured_client/_hooks/custom/clean_server_url_hook.py +++ b/src/unstructured_client/_hooks/custom/clean_server_url_hook.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Tuple from urllib.parse import ParseResult, urlparse, urlunparse diff --git a/src/unstructured_client/_hooks/custom/logger_hook.py b/src/unstructured_client/_hooks/custom/logger_hook.py index d39d2216..fc674998 100644 --- a/src/unstructured_client/_hooks/custom/logger_hook.py +++ b/src/unstructured_client/_hooks/custom/logger_hook.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from typing import Optional, Tuple, Union, DefaultDict diff --git a/src/unstructured_client/_hooks/custom/pdf_utils.py b/src/unstructured_client/_hooks/custom/pdf_utils.py index 288cbd6c..7258e89c 100644 --- a/src/unstructured_client/_hooks/custom/pdf_utils.py +++ b/src/unstructured_client/_hooks/custom/pdf_utils.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import logging from typing import cast, Generator, Tuple, Optional diff --git a/src/unstructured_client/_hooks/custom/suggest_defining_url.py b/src/unstructured_client/_hooks/custom/suggest_defining_url.py index 216ec13d..d768917e 100644 --- a/src/unstructured_client/_hooks/custom/suggest_defining_url.py +++ b/src/unstructured_client/_hooks/custom/suggest_defining_url.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Optional, Tuple, Union import httpx From cb06c7eadebc271537f413f56eaf158e05e218d8 Mon Sep 17 00:00:00 2001 From: John <43506685+Coniferish@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:59:24 -0400 Subject: [PATCH 2/5] update workflows --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e97b5474..9d96e9f8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ jobs: test_unit: strategy: matrix: - python-version: ["3.9","3.10","3.11"] + python-version: ["3.8", "3.9","3.10","3.11"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -47,7 +47,7 @@ jobs: test_integration: strategy: matrix: - python-version: ["3.9","3.10","3.11"] + python-version: ["3.8", "3.9","3.10","3.11"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From b47f3463a30ce65ff52648eda22272070a26d6b1 Mon Sep 17 00:00:00 2001 From: John <43506685+Coniferish@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:07:28 -0400 Subject: [PATCH 3/5] add more imports of 'annotations' and fix type hint --- .../integration/test_integration_freemium.py | 2 ++ _test_unstructured_client/unit/test_custom_hooks.py | 2 ++ src/unstructured_client/_hooks/custom/form_utils.py | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/_test_unstructured_client/integration/test_integration_freemium.py b/_test_unstructured_client/integration/test_integration_freemium.py index db981eea..8f05d6b2 100644 --- a/_test_unstructured_client/integration/test_integration_freemium.py +++ b/_test_unstructured_client/integration/test_integration_freemium.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import asyncio import json import os diff --git a/_test_unstructured_client/unit/test_custom_hooks.py b/_test_unstructured_client/unit/test_custom_hooks.py index 8c0b7a40..71788ed5 100644 --- a/_test_unstructured_client/unit/test_custom_hooks.py +++ b/_test_unstructured_client/unit/test_custom_hooks.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import re diff --git a/src/unstructured_client/_hooks/custom/form_utils.py b/src/unstructured_client/_hooks/custom/form_utils.py index 54fb06b3..83a01519 100644 --- a/src/unstructured_client/_hooks/custom/form_utils.py +++ b/src/unstructured_client/_hooks/custom/form_utils.py @@ -2,6 +2,7 @@ import logging from typing import Union +from typing_extensions import TypeAlias from requests_toolbelt.multipart.decoder import MultipartDecoder # type: ignore @@ -9,7 +10,7 @@ from unstructured_client.models import shared logger = logging.getLogger(UNSTRUCTURED_CLIENT_LOGGER_NAME) -FormData = dict[str, Union[str, shared.Files, list[str]]] +FormData: TypeAlias = dict[str, Union[str, shared.Files, list[str]]] PARTITION_FORM_FILES_KEY = "files" PARTITION_FORM_SPLIT_PDF_PAGE_KEY = "split_pdf_page" @@ -32,6 +33,7 @@ def get_page_range(form_data: FormData, key: str, max_pages: int) -> tuple[int, Returns: The range of pages to send in the request in the form (start, end) """ + _page_range = None try: _page_range = form_data.get(key) @@ -202,7 +204,7 @@ def parse_form_data(decoded_data: MultipartDecoder) -> FormData: form_data: FormData = {} for part in decoded_data.parts: - content_disposition = part.headers.get(b"Content-Disposition") + content_disposition = part.headers.get(b"Content-Disposition") # type: ignore if content_disposition is None: raise RuntimeError("Content-Disposition header not found. Can't split pdf file.") part_params = decode_content_disposition(content_disposition) From 976f68eebf97f5d7d1507292073d7943a5776ab0 Mon Sep 17 00:00:00 2001 From: John <43506685+Coniferish@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:16:22 -0400 Subject: [PATCH 4/5] typing --- src/unstructured_client/_hooks/custom/form_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unstructured_client/_hooks/custom/form_utils.py b/src/unstructured_client/_hooks/custom/form_utils.py index 83a01519..7f3e137b 100644 --- a/src/unstructured_client/_hooks/custom/form_utils.py +++ b/src/unstructured_client/_hooks/custom/form_utils.py @@ -10,7 +10,7 @@ from unstructured_client.models import shared logger = logging.getLogger(UNSTRUCTURED_CLIENT_LOGGER_NAME) -FormData: TypeAlias = dict[str, Union[str, shared.Files, list[str]]] +FormData: TypeAlias = "dict[str, Union[str, shared.Files, list[str]]]" PARTITION_FORM_FILES_KEY = "files" PARTITION_FORM_SPLIT_PDF_PAGE_KEY = "split_pdf_page" From 74045f361b6a8194e1320de449db7c19677fd5ae Mon Sep 17 00:00:00 2001 From: John <43506685+Coniferish@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:39:10 -0400 Subject: [PATCH 5/5] add TYPE_CHECKING block --- src/unstructured_client/_hooks/custom/form_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unstructured_client/_hooks/custom/form_utils.py b/src/unstructured_client/_hooks/custom/form_utils.py index 7f3e137b..2d44acce 100644 --- a/src/unstructured_client/_hooks/custom/form_utils.py +++ b/src/unstructured_client/_hooks/custom/form_utils.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import Union +from typing import TYPE_CHECKING from typing_extensions import TypeAlias from requests_toolbelt.multipart.decoder import MultipartDecoder # type: ignore @@ -9,6 +9,9 @@ from unstructured_client._hooks.custom.common import UNSTRUCTURED_CLIENT_LOGGER_NAME from unstructured_client.models import shared +if TYPE_CHECKING: + from typing import Union + logger = logging.getLogger(UNSTRUCTURED_CLIENT_LOGGER_NAME) FormData: TypeAlias = "dict[str, Union[str, shared.Files, list[str]]]"