Skip to content

Commit a9bc168

Browse files
committed
Got rid of the internal datetimetz type.
1 parent a032d2e commit a9bc168

3 files changed

Lines changed: 852 additions & 1221 deletions

File tree

Include/datetime.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ typedef struct
4242
PyObject_HEAD /* a pure abstract base clase */
4343
} PyDateTime_TZInfo;
4444

45-
typedef struct
46-
{
47-
PyObject_HEAD
48-
long hashcode;
49-
unsigned char data[_PyDateTime_DATE_DATASIZE];
50-
} PyDateTime_Date;
51-
5245

5346
/* The datetime and time types have hashcodes, and an optional tzinfo member,
5447
* present if and only if hastzinfo is true.
@@ -88,25 +81,35 @@ typedef struct
8881
PyObject *tzinfo;
8982
} PyDateTime_Time; /* hastzinfo true */
9083

91-
/* XXX The date type will be reworked similarly. */
9284

85+
/* All datetime objects are of PyDateTime_DateTimeType, but that can be
86+
* allocated in two ways too, just like for time objects above. In addition,
87+
* the plain date type is a base class for datetime, so it must also have
88+
* a hastzinfo member (although it's unused there).
89+
*/
9390
typedef struct
9491
{
95-
PyObject_HEAD
96-
long hashcode;
92+
_PyTZINFO_HEAD
93+
unsigned char data[_PyDateTime_DATE_DATASIZE];
94+
} PyDateTime_Date;
95+
96+
#define _PyDateTime_DATETIMEHEAD \
97+
_PyTZINFO_HEAD \
9798
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
98-
} PyDateTime_DateTime;
9999

100100
typedef struct
101101
{
102-
PyObject_HEAD
103-
long hashcode;
104-
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
102+
_PyDateTime_DATETIMEHEAD
103+
} _PyDateTime_BaseDateTime; /* hastzinfo false */
104+
105+
typedef struct
106+
{
107+
_PyDateTime_DATETIMEHEAD
105108
PyObject *tzinfo;
106-
} PyDateTime_DateTimeTZ;
109+
} PyDateTime_DateTime; /* hastzinfo true */
107110

108111

109-
/* Apply for date, datetime, and datetimetz instances. */
112+
/* Apply for date and datetime instances. */
110113
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
111114
((PyDateTime_Date*)o)->data[1])
112115
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
@@ -135,9 +138,6 @@ typedef struct
135138
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
136139
#define PyDateTime_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeType)
137140

138-
#define PyDateTimeTZ_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeTZType)
139-
#define PyDateTimeTZ_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeTZType)
140-
141141
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
142142
#define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
143143

Lib/test/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ def test_pickling(self):
20762076
tinfo = PicklableFixedOffset(-300, 'cookie')
20772077
orig = self.theclass(*args, **{'tzinfo': tinfo})
20782078
state = orig.__getstate__()
2079-
derived = self.theclass(1, 1, 1)
2079+
derived = self.theclass(1, 1, 1, tzinfo=FixedOffset(0, "", 0))
20802080
derived.__setstate__(state)
20812081
self.assertEqual(orig, derived)
20822082
self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset))

0 commit comments

Comments
 (0)