STINNER Victor added the comment: > Would option (1) work if wrap 1 and 1.0 in a tuple? In a list? In a custom > collection?
Right now, the Python compiler is quite limited. It only produces constants for integers and strings, not complex types. The peephole optimizers is responsible to produce tuple and frozenset constants, and the optimizer is more naive. It doesn't try to merge constants, nor remove items from co_consts to only keep the new container. Example: >>> def f(): ... return (1,2,3) ... >>> f.__code__.co_consts (None, 1, 2, 3, (1, 2, 3)) 1, 2, 3 constants are kept, whereas only (1, 2, 3) constant is used. Test with my patch: >>> f1, f2 = lambda x: x in {1,}, lambda x: x in {1.0,} >>> >>> f1.__code__ is f2.__code__ False >>> f1.__code__.co_consts (None, 1, frozenset({1})) >>> f2.__code__.co_consts (None, 1.0, frozenset({1.0})) The frozenset are different are expected. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25843> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com