fix: preserve SDK imports on supported Python versions#427
Open
DivyamTalwar wants to merge 1 commit into
Open
Conversation
Constraint: The Python SDK metadata declares >=3.8, while Python 3.9 import failed on runtime-evaluated newer annotation syntax. Rejected: Raise the SDK Python floor to >=3.10 | This keeps the existing published support contract and only changes annotation syntax. Confidence: high Scope-risk: narrow Directive: Add a minimum-version SDK import or collection CI job before relying on future syntax changes. Tested: Python 3.9 import smoke; Python 3.9 SDK live-test collection with SKIP_LIVE_TESTS=1; SDK tests with live tests skipped (74 passed, 26 skipped); py_compile on changed Python files; Python 3.8 grammar parse and annotation compatibility scan; changelog markdown render; git diff --check. Not-tested: Python 3.8 runtime import because uv interpreter download did not complete locally; ty has existing unrelated SDK diagnostics; ruff is unavailable locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Python SDK declares
requires-python = ">=3.8", but a few runtime-evaluated annotations used newer Python syntax. On Python 3.9, importingmorphikfailed immediately withTypeError: unsupported operand type(s) for |: 'type' and 'type'before users could create a client.This replaces those annotations with
typingequivalents (Union,Tuple, andList) and adds a short SDK changelog note. There is no API behavior change.Changes
FinalChunkResult.content: str | PILImagewithUnion[str, PILImage].tuple[str, Document]toTuple[str, Document].list[str]toList[str]so those modules collect on older supported interpreters.UnreleasedPython SDK changelog entry for the compatibility fix.Why this matters
Users on Python versions allowed by the SDK metadata should be able to import the package. This fixes a reproduced import-time compatibility regression for Python 3.9 and removes the same newer annotation forms from the touched SDK/test surface.
Tests
Commands run:
uv run --python 3.9 --with pytest --with httpx --with pyjwt --with 'pydantic>=2.10.3' --with 'pillow>=10.4.0' --project sdks/python python - <<'PY' ... import morphik ... PY— failed before the fix withTypeError: unsupported operand type(s) for |: 'type' and 'type'.uv run --python 3.9 --project sdks/python python -c "import morphik; from morphik.sync import Morphik; from morphik.async_ import AsyncMorphik; print('py39 import ok')"— passed.uv run --python 3.9 --project sdks/python pytest sdks/python/morphik/tests/test_scoped_ops_unit.py::test_sync_client_accepts_plain_http_uri_without_auth -q— passed.SKIP_LIVE_TESTS=1 uv run --python 3.9 --project sdks/python pytest sdks/python/morphik/tests/test_sync.py sdks/python/morphik/tests/test_async.py --collect-only -q— passed, 26 tests collected..venv/bin/python -m pytest sdks/python/morphik/tests/test_scoped_ops_unit.py -q— passed, 49 tests.SKIP_LIVE_TESTS=1 .venv/bin/python -m pytest sdks/python/morphik/tests -q— passed, 74 passed / 26 skipped..venv/bin/python -m py_compile sdks/python/morphik/_internal.py sdks/python/morphik/sync.py sdks/python/morphik/async_.py sdks/python/morphik/tests/test_sync.py sdks/python/morphik/tests/test_async.py— passed.sdks/python/morphik/**/*.pyusingast.parse(..., feature_version=(3, 8))— passed.sdks/python/morphik— passed..venv/bin/markdown-it sdks/python/CHANGELOG.md >/tmp/sdk-changelog-pr12.html— passed.git diff --check— passed.Checks not completed:
uv run --python 3.8 --project sdks/python ...— not completed because the localcpython-3.8.20-macos-aarch64download remained silent for multiple minutes and was interrupted. The Python 3.9 runtime failure is reproduced/fixed, and source-level Python 3.8 grammar/annotation scans pass.uv run ty check ...— failed on existing SDK typing diagnostics unrelated to this diff (_prepare_file_for_uploadreturn type,CompletionResponserequiredusage, sync/asyncget_inforeturn type, and migration status literal).uv run ruff check ...— not run successfully becauseruffis not installed in the local project environment.Risk
Risk level: low.
This is an annotation-only compatibility fix plus a changelog entry. It does not change request payloads, parsing behavior, public APIs, dependencies, auth, or network behavior. Rollback is straightforward if maintainers choose to raise the SDK Python floor instead.
Issue
No existing issue. This was discovered during repository analysis.
This does not address or close issue #155, which concerns a hosted documentation redirect page that is not present in this repository.
Notes for maintainers
Follow-up worth considering: add a small SDK import/test-collection CI job for the declared minimum supported Python version, so future annotation syntax regressions are caught automatically.