Repository navigation
R23-T021: Make data_structures/linked_list/skip_list.py fully typed - #71
Open
mohammedsohail0301-dot wants to merge 2 commits into
Open
mohammedsohail0301-dot wants to merge 2 commits into
mohammedsohail0301-dot wants to merge 2 commits into
Conversation
- Add type hints for __iter__, _locate_node, traverse_keys, and is_sorted - Fix find() parameter key type from VT to KT and add doctest - Add work/R23-T021 evidence and findings
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.
Describe your change
Checklist
Description
Adds accurate parameter and return type annotations to all four unhinted functions in
data_structures/linked_list/skip_list.py:__iter__,_locate_node,traverse_keys, andis_sorted, keeping generics consistent withSkipList[KT, VT]. Fixes a real bug exposed infind()where parameterkeywas typed asVTinstead ofKT, and adds a doctest verifying lookup on aSkipList[str, int].Related Issue
Fixes: #3
Type of Change
Changes Made
data_structures/linked_list/skip_list.py:SkipList.__iter__(self) -> Iterator[KT]: Added return type hint usingcollections.abc.Iterator[KT]andcast(KT, node.forward[0].key)so that__iter__consistently yieldsKT.SkipList._locate_node(self, key: KT) -> tuple[Node[KT, VT] | None, list[Node[KT, VT]]]: Annotated parameterkey: KT.SkipList.find(self, key: KT) -> VT | None: Fixed parameter type fromVTtoKT(exposed by type checking_locate_node(key)), and added a doctest verifying lookup onSkipList[str, int].traverse_keys(node: Node[str, int]) -> Iterator[str]: Insidetest_delete_doesnt_leave_dead_nodes(), annotated parameter and return with concrete types.is_sorted(lst: list[int]) -> bool: Insidetest_iter_always_yields_sorted_values(), annotated parameter aslist[int]and return type asbool.work/R23-T021/: AddedFINDINGS.md,ty_before.txt,ty_after.txt, andtest_output.txtdocumenting before/after type checking runs and test results.Screenshots / Recordings
Not applicable (no UI changes).
Testing
uv run --python 3.15 --with ty ty check data_structures/linked_list/skip_list.py-> 0 diagnostics for the file.uv run --python 3.15 pytest -v data_structures/linked_list/skip_list.py-> 16/16 passed.uv run --python 3.15 python -m doctest -v data_structures/linked_list/skip_list.py-> 36/36 passed.Additional Notes
SkipList.__iter__,node.forward[0].keycarries typeKT | strbecauseNode.keydefaults to"root"onself.head. Usingcast(KT, ...)reflects that only user-inserted nodes (key: KT) exist innode.forward._locate_node(key: KT)directly exposed a type bug infind(key: VT):findwas passingkey: VTinto_locate_node(key: KT). Correctingfind(key: KT)resolves this issue.R23-T021-upstreamcontaining only the code change (nowork/folder) has been created and pushed for a later upstream PR.