[pypy-commit] pypy default: Rewrite this code to be faster and more readable

alex_gaynor noreply at buildbot.pypy.org
Fri Aug 30 19:56:44 CEST 2013


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r66682:d76da246d42e
Date: 2013-08-30 10:52 -0700
http://bitbucket.org/pypy/pypy/changeset/d76da246d42e/

Log:	Rewrite this code to be faster and more readable

diff --git a/lib-python/2.7/uuid.py b/lib-python/2.7/uuid.py
--- a/lib-python/2.7/uuid.py
+++ b/lib-python/2.7/uuid.py
@@ -127,8 +127,12 @@
         overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
         """
 
-        if [hex, bytes, bytes_le, fields, int].count(None) != 4:
-            raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
+        if (
+            ((hex is not None) + (bytes is not None) + (bytes_le is not None) +
+             (fields is not None) + (int is not None)) != 1
+        ):
+            raise TypeError('need exactly one of hex, bytes, bytes_le, fields,'
+                            ' or int')
         if hex is not None:
             hex = hex.replace('urn:', '').replace('uuid:', '')
             hex = hex.strip('{}').replace('-', '')


More information about the pypy-commit mailing list