One function

Array in mlarocca/grokking_data_structures

The author described this change as Fix Array constructor for unicode typecode 'u'. It counts as a record because the check below fails on the code as it stood at f6f56d488 and passes on 7d0b1891a, with nothing else changed between the two runs.

Fix saved2026-03-04
Sharing licenceApache-2.0 · LICENSE
Change size+2 1

What the code was meant to do, written into the code itself as a docstring

Return a new array whose items are restricted by typecode, and that can contain at most `size` elements. Arrays behave very much like Python list, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which is a single character. The following type codes are defined: Type code C Type Minimum size in bytes 'b' signed integer 1 'B' unsigned integer 1 'u' Unicode character 2 'h' signed integer 2 'H' unsigned integer 2 'i' signed integer 2 'I' unsigned integer 2 'l' signed integer 4 'L' unsigned integer 4 'q' signed integer 8 'Q' unsigned integer 8 'f' floating point 4 'd' floating point 8 Parameters: max_capacity (int): The maximum number of elements the array can hold. typecode (str, optional): The typecode of the array. Defaults to 'l' for int.

The change

3232 if size <= 0:
3333 raise ValueError(f'Invalid array size (must be positive): {size}')
3434 self._size = size
35- self._array = array.array(typecode, [0] * size)
35+ default_value = '\x00' if typecode == 'u' else 0
36+ self._array = array.array(typecode, [default_value] * size)
3637
3738
3839 def __len__(self):

The check that tells the two apart

failpass·python/tests/test_core.py::TestArray::test_get_item_valid

Check file python/tests/test_core.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf6f56d488ae4c4ec5bbc297b34ca13f595554278
Broken version dated2025-11-07
Modulepython.arrays.core
Units changedArray
Fingerprint2f9005996a00bddb
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.