Whole file

mina86/pygtrie

The author described this change as Fix StringTrie.copy ignoring separator and improve PrefixSet.copy. It counts as a record because the check below fails on the code as it stood at fdb6991dd and passes on e29637950, with nothing else changed between the two runs.

Fix saved2019-05-27
Sharing licenceApache-2.0 · LICENSE
Change size+9 4

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

Fix StringTrie.copy ignoring separator and improve PrefixSet.copy

The change

14481448 trie[key] = value
14491449 return trie
14501450
1451+ def copy(self):
1452+ return self.__class__(self, separator=self._separator)
1453+
14511454 def _path_from_key(self, key):
14521455 return key.split(self._separator)
14531456
14681471 behaviour for element deletion.
14691472 """
14701473
1471- def __init__(self, iterable=None, factory=Trie, **kwargs):
1474+ def __init__(self, iterable=(), factory=Trie, **kwargs):
14721475 """Initialises the prefix set.
14731476
14741477 Args:
14781481 kwargs: Additional keyword arguments passed to the factory function.
14791482 """
14801483 trie = factory(**kwargs)
1481- if iterable:
1482- trie.update((key, True) for key in iterable)
1484+ for key in iterable:
1485+ trie[key:] = True
14831486 self._trie = trie
14841487
14851488 def copy(self):
14861489 """Returns a copy of the prefix set."""
1487- return self.__class__(self._trie, factory=self._trie.__class__)
1490+ cpy = super(PrefixSet, self).__new__(type(self))
1491+ cpy._trie = self._trie.copy() # pylint: disable=protected-access
1492+ return cpy
14881493
14891494 def clear(self):
14901495 """Removes all keys from the set."""

The check that tells the two apart

failpass·test.py::StringTrieTestCase::test_basics_CopyOfTrie

Check file test.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 itfdb6991dd4ae8a15ba9fbc0266ea0dfdb8a6d75a
Broken version dated2019-05-27
Modulepygtrie
Units changedPrefixSet, StringTrie
Fingerprintb5e4b707b43e65b4
Checked2026-08-18 by goldset/0.1

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

Other bugs found in mina86/pygtrie