[Python-Dev] Re: Re: Prospective Peephole Transformation
Fredrik Lundh
fredrik at pythonware.com
Sun Feb 20 13:07:17 CET 2005
Martin v. Löwis wrote:
>> I'd say that this explains why it would still make sense to let the code generator change
>> "x in (a, b, c)" to "x == a or x == b or x == c", as long as a, b, and c are all integers.
>
> How often does that happen in real code?
don't know, but it happens:
[fredrik at brain Python-2.4]$ grep "if.*in *([0-9]" Lib/*.py
Lib/BaseHTTPServer.py: if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
Lib/asyncore.py: if err in (0, EISCONN):
Lib/mimify.py: if len(args) not in (0, 1, 2):
Lib/sunau.py: if nchannels not in (1, 2, 4):
Lib/sunau.py: if sampwidth not in (1, 2, 4):
Lib/urllib2.py: if code not in (200, 206):
Lib/urllib2.py: if (code in (301, 302, 303, 307) and m in ("GET", "HEAD")
Lib/whichdb.py: if magic in (0x00061561, 0x61150600):
Lib/whichdb.py: if magic in (0x00061561, 0x61150600):
[fredrik at brain Python-2.4]$ grep "if.*in *\[[0-9]" Lib/*.py
Lib/decimal.py: if value[0] not in [0,1]:
Lib/smtplib.py: if code not in [235, 503]:
judging from the standard library, "string in string tuple/list" is a lot more common.
</F>
More information about the Python-Dev
mailing list