Author terry.reedy
Recipients cheryl.sabella, terry.reedy
Date 2018-02-24.22:53:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519512813.2.0.467229070634.issue32940@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2018-02-24 22:53:33terry.reedysetrecipients: + terry.reedy, cheryl.sabella
2018-02-24 22:53:33terry.reedysetmessageid: <1519512813.2.0.467229070634.issue32940@psf.upfronthosting.co.za>
2018-02-24 22:53:33terry.reedylinkissue32940 messages
2018-02-24 22:53:33terry.reedycreate