Brian Kearns avatar Brian Kearns committed b628683

use slots for datetime objects, test

Comments (0)

Files changed (2)

lib_pypy/datetime.py

     felt like it.
     """
 
+    __slots__ = '_days', '_seconds', '_microseconds'
+
     def __new__(cls, days=0, seconds=0, microseconds=0,
                 # XXX The following should only be used as keyword args:
                 milliseconds=0, minutes=0, hours=0, weeks=0):
     year, month, day
     """
 
+    __slots__ = '_year', '_month', '_day'
+
     def __new__(cls, year, month=None, day=None):
         """Constructor.
 
     Subclasses must override the name(), utcoffset() and dst() methods.
     """
 
+    __slots__ = ()
+
     def tzname(self, dt):
         "datetime -> string name of time zone."
         raise NotImplementedError("tzinfo subclass must override tzname()")
     hour, minute, second, microsecond, tzinfo
     """
 
+    __slots__ = '_hour', '_minute', '_second', '_microsecond', '_tzinfo'
+
     def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
         """Constructor.
 
     instance of a tzinfo subclass. The remaining arguments may be ints or longs.
     """
 
+    __slots__ = date.__slots__ + time.__slots__
+
     def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
                 microsecond=0, tzinfo=None):
         if isinstance(year, str):

pypy/module/test_lib_pypy/test_datetime.py

     expected = "datetime.datetime(1, 2, 3, 0, 0)"
     assert repr(datetime.datetime(1,2,3)) == expected
 
+def test_attributes():
+    a = datetime.date.today()
+    raises(AttributeError, 'a.abc = 1')
+    a = datetime.time()
+    raises(AttributeError, 'a.abc = 1')
+    a = datetime.tzinfo()
+    raises(AttributeError, 'a.abc = 1')
+    a = datetime.datetime.utcnow()
+    raises(AttributeError, 'a.abc = 1')
+    a = datetime.timedelta()
+    raises(AttributeError, 'a.abc = 1')
+
 def test_strptime():
     import time, sys
     if sys.version_info < (2, 6):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.