[Python-checkins] r82619 - sandbox/branches/py3k-datetime/datetime.py

alexander.belopolsky python-checkins at python.org
Wed Jul 7 01:44:27 CEST 2010


Author: alexander.belopolsky
Date: Wed Jul  7 01:44:26 2010
New Revision: 82619

Log:
Use custom sentinel instead of varargs in timezone()

Modified:
   sandbox/branches/py3k-datetime/datetime.py

Modified: sandbox/branches/py3k-datetime/datetime.py
==============================================================================
--- sandbox/branches/py3k-datetime/datetime.py	(original)
+++ sandbox/branches/py3k-datetime/datetime.py	Wed Jul  7 01:44:26 2010
@@ -1784,18 +1784,13 @@
 class timezone(tzinfo):
     __slots__ = '_offset', '_name'
 
-    def __init__(self, offset, *args):
-        # Reproduce C behavior
-        n = len(args)
-        if n > 1:
-            raise TypeError("timezone() takes at most 2 arguments (%d given)"
-                            % n)
-        if n == 0:
+    # Sentinel value to disallow None
+    _NoneGiven = object()
+    def __init__(self, offset, name=_NoneGiven):
+        if name is self._NoneGiven:
             name = None
-        else:
-            name = args[0]
-            if not isinstance(name, str):
-                raise TypeError("name must be a string")
+        elif not isinstance(name, str):
+            raise TypeError("name must be a string")
         if isinstance(offset, timedelta):
             if self._minoffset <= offset <= self._maxoffset:
                 if (offset.microseconds != 0 or


More information about the Python-checkins mailing list