Patches item #1548082, was opened at 2006-08-28 12:38 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1548082&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 3000 Status: Open Resolution: None Priority: 5 Submitted By: Georg Brandl (gbrandl) Assigned to: Guido van Rossum (gvanrossum) Summary: "if x in setliteral" peepholer optimization Initial Comment: Like "for x in tuple_or_list", this patch rewrites "for x in set" to use a constant frozenset. ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2006-08-29 16:26 Message: Logged In: YES user_id=80475 This implementation too simplistic, you need to use a subclass of frozenset that overrides the __contains__() method to return False when the argument is not hashable. Otherwise, you end-up with a semantic change for: x = {} if x in [1,2,3]: print 'Not Found' ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2006-08-29 14:08 Message: Logged In: YES user_id=849994 Argh. Like in the py3k mail, I confusedly interchanged "for x in set" and "if x in set". if x in [1,2,3] does get special treatment, and optimizing the "in" test does make sense. ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2006-08-29 13:24 Message: Logged In: YES user_id=6380 Um, "for x in [1,2,3]" doesn't get any treatment. What would be the point of writing "for x in {1,2,3}" anyway? I'd rather reject this as premature optimization. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1548082&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches