Repository navigation
Sync hashtable with the updated tutorial (Python 3.15) - #923
Merged
Merged
Conversation
- BLANK and DELETED are built-in sentinel() objects instead of object() - HashTable.pairs in 05_separate_chaining unpacks the buckets in a set comprehension (PEP 798) - requirements.txt: pytest 9.1.1, pytest-unordered 0.8.0 on Python 3.15 - README: the code requires Python 3.15 or later - pyproject.toml: exclude hashtable from ruff, like the python315-* folders (ruff 0.14.1 targets py314: sentinel is F821 there, and unpacking in a comprehension is a syntax error)
A shallow copy of the list still shares mutable values, so a caller could change the table through it (reported by a reader in 2022). From the next step on, .pairs is a set, whose members must be hashable, so a shallow copy is enough there.
bzaczynski
approved these changes
Oct 26, 2026
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.
Brings
hashtable/in line with the Python 3.15 update of Build a Hash Table in Python With TDD and the new video course built from it.What changed
BLANK(the prototype steps 02-05) andDELETED(linear probing, autoresize, load factor) are built-insentinel()objects instead ofobject().HashTable.pairsin01_hashtable_prototype/07_use_defensive_copyingreturnscopy.deepcopy(...)of the list: a shallow copy still shares mutable values, so a caller could change the table through it (a reader's comment on the tutorial). From folder 08 on,.pairsis a set, whose members must be hashable, so a shallow copy is enough there.HashTable.pairsin05_separate_chainingunpacks the buckets in a set comprehension,{*bucket for bucket in self._buckets}(PEP 798).requirements.txtpins pytest 9.1.1 and pytest-unordered 0.8.0, resolved for Python 3.15.python3.15.pyproject.tomlexcludeshashtablefrom ruff, likepython315-frozendict/,python315-lazy-imports, andpython315-new-features. Ruff 0.14.1 targets py314, wheresentinelis undefined (F821) and unpacking in a comprehension is a syntax error.The folders keep their structure (
matchwith_find()), as the tutorial describes them.How it was verified
requirements.txt. Every folder's tests pass with the README's commands, with the same counts as before: the prototype steps 01-12 (PYTHONHASHSEED=128) give 3, 6, 14, 16, 17, 18, 20, 29, 34, 38, 42, and 49 passed, then 57, 58, 67, 62, and 62 passed for02-06.hash_distribution.pyruns.uvx ruff@0.14.1 check .andformat --check .are clean.The tutorial's own update is a separate, unpublished draft in the CMS that uses this code: python-hash-table-update (an
[UPDATE]clone of the live post).