[Python-Dev] Updated PEP 509 (original) (raw)
Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Apr 18 10:38:54 EDT 2016
- Previous message (by thread): [Python-Dev] Updated PEP 509
- Next message (by thread): [Python-Dev] [Python-ideas] pep 7 line break suggestion differs from pep 8
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 18 April 2016 at 12:46, Jim J. Jewett <jimjjewett at gmail.com> wrote:
* I removed the dict[key]=value; dict[key]=value. It's really a micro-optimization. I also fear that Raymond will complain because it adds an if in the hot code of dict, and the dict type is very important for Python performance. That is an acceptable answer. Though I really do prefer explicitly refusing to promise either way when the replacement/replaced objects are ==. dicts (and other collections) already assume sensible ==, even explicitly allowing self-matches of objects that are not equal to themselves. I don't like the idea of making new promises that violate (or rely on violations of) that sensible == assumption.
dicts make assumptions about the behaviour of eq for the keys but not for the values (on which no assumptions are made). The only way to replace a key in a dict with another equal key (having a well-behaved hash function) is to pop the key out and then insert the new key so it's not possible to replace a key with another equal key without bumping the version twice. So presumably you're referring to the values here right?
The purpose of the PEP is to be able to guard for changes to namespaces which are implemented as dicts. So if builtins.dict['abs'] is replaced by foo then we don't care what foo.eq says about the situation: any optimisation that assumed builtins.abs was not monkeypatched is invalidated. That's why the version update is needed. Without it the version cannot be relied upon as an optimisation guard. Consider:
class MyAbs: def eq(self, other): return True def call(self, arg): return - arg
builtins.abs = MyAbs()
-- Oscar
- Previous message (by thread): [Python-Dev] Updated PEP 509
- Next message (by thread): [Python-Dev] [Python-ideas] pep 7 line break suggestion differs from pep 8
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]