Skip to content

Commit 6e1fa29

Browse files
authored
feat: py 3.8 support (#187)
Adds `from __future__ import annotations` to all custom code files to enable forward references to contemporary type hints such as `dict` and ` list`. Also fixes a `TypeAlias` and enables python `3.8` checks (resolves #138)
1 parent 0c95c76 commit 6e1fa29

File tree

10 files changed

+26
-5
lines changed

10 files changed

+26
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
test_unit:
2121
strategy:
2222
matrix:
23-
python-version: ["3.9","3.10","3.11"]
23+
python-version: ["3.8", "3.9","3.10","3.11"]
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v4
@@ -47,7 +47,7 @@ jobs:
4747
test_integration:
4848
strategy:
4949
matrix:
50-
python-version: ["3.9","3.10","3.11"]
50+
python-version: ["3.8", "3.9","3.10","3.11"]
5151
runs-on: ubuntu-latest
5252
steps:
5353
- uses: actions/checkout@v4

_test_unstructured_client/integration/test_decorators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import httpx
24
import json
35
import pytest

_test_unstructured_client/integration/test_integration_freemium.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import json
35
import os

_test_unstructured_client/unit/test_custom_hooks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import re
35

_test_unstructured_client/unit/test_split_pdf_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import io
35
import logging

src/unstructured_client/_hooks/custom/clean_server_url_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Tuple
24
from urllib.parse import ParseResult, urlparse, urlunparse
35

src/unstructured_client/_hooks/custom/form_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import Union
4+
from typing import TYPE_CHECKING
5+
from typing_extensions import TypeAlias
56

67
from requests_toolbelt.multipart.decoder import MultipartDecoder # type: ignore
78

89
from unstructured_client._hooks.custom.common import UNSTRUCTURED_CLIENT_LOGGER_NAME
910
from unstructured_client.models import shared
1011

12+
if TYPE_CHECKING:
13+
from typing import Union
14+
1115
logger = logging.getLogger(UNSTRUCTURED_CLIENT_LOGGER_NAME)
12-
FormData = dict[str, Union[str, shared.Files, list[str]]]
16+
FormData: TypeAlias = "dict[str, Union[str, shared.Files, list[str]]]"
1317

1418
PARTITION_FORM_FILES_KEY = "files"
1519
PARTITION_FORM_SPLIT_PDF_PAGE_KEY = "split_pdf_page"
@@ -32,6 +36,7 @@ def get_page_range(form_data: FormData, key: str, max_pages: int) -> tuple[int,
3236
Returns:
3337
The range of pages to send in the request in the form (start, end)
3438
"""
39+
_page_range = None
3540
try:
3641
_page_range = form_data.get(key)
3742

@@ -202,7 +207,7 @@ def parse_form_data(decoded_data: MultipartDecoder) -> FormData:
202207
form_data: FormData = {}
203208

204209
for part in decoded_data.parts:
205-
content_disposition = part.headers.get(b"Content-Disposition")
210+
content_disposition = part.headers.get(b"Content-Disposition") # type: ignore
206211
if content_disposition is None:
207212
raise RuntimeError("Content-Disposition header not found. Can't split pdf file.")
208213
part_params = decode_content_disposition(content_disposition)

src/unstructured_client/_hooks/custom/logger_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
from typing import Optional, Tuple, Union, DefaultDict
35

src/unstructured_client/_hooks/custom/pdf_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import io
24
import logging
35
from typing import cast, Generator, Tuple, Optional

src/unstructured_client/_hooks/custom/suggest_defining_url.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Optional, Tuple, Union
24

35
import httpx

0 commit comments

Comments
 (0)