Modernize type annotations (PEP 585/604) - #5
Merged
Conversation
The package requires Python >=3.10, so the legacy typing generics and Optional[...] unions are no longer needed: - Optional[X] -> X | None - Dict/Tuple/List[...] -> dict/tuple/list[...] - typing.Callable / typing.Iterator -> collections.abc equivalents Also fixes two defects found while doing this: - js_parse.replace_ids_in_code was annotated `-> (str, dict)`, a tuple *of types* rather than a type. Now `-> tuple[str, dict]`. - find_and_replace_ids imported `Union`, which was never used. No behaviour change. Verified all modules still import and that every touched signature evaluates at runtime (X | None is evaluated eagerly in annotations, so this would fail loudly on <3.10). Formatting is left alone: the same 3 files already fail black on master, so that drift is pre-existing and is CI's job, not this change's. Claude-Session: https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU
Joins the existing exploratory notebooks under misc/. Checked for credentials and machine-local paths before committing; none present. Claude-Session: https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU
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.
What
The package declares
requires-python = ">=3.10", so the legacy typing spellings are no longer needed:Optional[X]→X | NoneDict/Tuple/List[...]→dict/tuple/list[...]typing.Callable/typing.Iterator→collections.abcequivalentsTwo defects fixed along the way
js_parse.replace_ids_in_codewas annotated-> (str, dict)— a tuple of types, not a type. Now-> tuple[str, dict].find_and_replace_idsimportedUnion, which was never used.Verification
pytest: 3 passed.jy.ts_parse(tree-sitter).inspect.signature. This matters:X | Nonein a signature is evaluated eagerly at def-time, so on <3.10 it would raiseTypeErrorrather than fail silently. It evaluates cleanly.compileallclean.No behaviour change.
Formatting
Deliberately not reformatted. The same 3 files already fail
blackonmaster, so that drift is pre-existing and belongs to CI's format step, not to this diff.Provenance
This started as uncommitted work in a local worktree that had fallen 8 commits behind
master, overlapping the same three files. Rather than force a conflicted merge, the transformation was re-derived against currentmaster(which had since reformatted to double quotes), and extended to cover the remaining occurrences so the package is now consistent.https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU