Terry J. Reedy <tjre...@udel.edu> added the comment: I forget about this defaultdict behavior: "this value is inserted in the dictionary for the key, and returned." Reason: when default_factory returns a mutable, d[key] must return the same possibly mutated object with each call. I agree that defaultdict is not the right replacement.
We need to pass to str.translate a dict that can be used by subscripting, newchar = d[char]. So partial(non-defaults.get, default_value) will not work. Instead, we need a __getitem__ that returns the same. In msg312444 I suggested simplifying STPM (including the name) because it has unneeded complexity. Remove the buggy .get override. Combine the _get stuff in __init__ (also removed) with current __getitem__ and simplify and we get what we actually need (untested, at yet). def __getitem__ return self._non_defaults.get(self._default_value) Actually, we could hard-code the default value as 'X' as we never need anything else. How about ParseMap for the name? ---------- stage: patch review -> needs patch title: IDLE: pyparse - replace StringTranslatePseudoMapping with defaultdict -> IDLE: pyparse - simplify StringTranslatePseudoMapping _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32940> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com