mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Got rid of the timetz type entirely. This was a bit trickier than I
hoped it would be, but not too bad. A test had to change: time.__setstate__() can no longer add a non-None tzinfo member to a time object that didn't already have one, since storage for a tzinfo member doesn't exist in that case.
This commit is contained in:
		
							parent
							
								
									a5e8bb94e5
								
							
						
					
					
						commit
						37f398282b
					
				
					 3 changed files with 369 additions and 504 deletions
				
			
		|  | @ -27,6 +27,11 @@ | ||||||
| /* # of bytes for year, month, day, hour, minute, second, and usecond. */ | /* # of bytes for year, month, day, hour, minute, second, and usecond. */ | ||||||
| #define _PyDateTime_DATETIME_DATASIZE 10 | #define _PyDateTime_DATETIME_DATASIZE 10 | ||||||
| 
 | 
 | ||||||
|  | #define _PyTZINFO_HEAD		\ | ||||||
|  | 	PyObject_HEAD		\ | ||||||
|  | 	long hashcode;		\ | ||||||
|  | 	char hastzinfo;		/* boolean flag */ | ||||||
|  | 
 | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
| 	PyObject_HEAD | 	PyObject_HEAD | ||||||
|  | @ -49,20 +54,23 @@ typedef struct | ||||||
| 	PyObject *tzinfo; | 	PyObject *tzinfo; | ||||||
| } PyDateTime_DateTimeTZ; | } PyDateTime_DateTimeTZ; | ||||||
| 
 | 
 | ||||||
| typedef struct | 
 | ||||||
| { | 
 | ||||||
| 	PyObject_HEAD | #define _PyDateTime_TIMEHEAD	\ | ||||||
| 	long hashcode; | 	_PyTZINFO_HEAD		\ | ||||||
| 	unsigned char data[_PyDateTime_TIME_DATASIZE]; | 	unsigned char data[_PyDateTime_TIME_DATASIZE]; | ||||||
| } PyDateTime_Time; |  | ||||||
| 
 | 
 | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
| 	PyObject_HEAD | 	_PyDateTime_TIMEHEAD | ||||||
| 	long hashcode; | } _PyDateTime_BaseTime;		/* hastzinfo false */ | ||||||
| 	unsigned char data[_PyDateTime_TIME_DATASIZE]; | 
 | ||||||
|  | typedef struct | ||||||
|  | { | ||||||
|  | 	_PyDateTime_TIMEHEAD | ||||||
| 	PyObject *tzinfo; | 	PyObject *tzinfo; | ||||||
| } PyDateTime_TimeTZ; | } PyDateTime_Time;		/* hastzinfo true */ | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
|  | @ -92,7 +100,7 @@ typedef struct | ||||||
|          (((PyDateTime_DateTime*)o)->data[8] << 8)  |	\ |          (((PyDateTime_DateTime*)o)->data[8] << 8)  |	\ | ||||||
|           ((PyDateTime_DateTime*)o)->data[9]) |           ((PyDateTime_DateTime*)o)->data[9]) | ||||||
| 
 | 
 | ||||||
| /* Apply for time and timetz instances. */ | /* Apply for time instances. */ | ||||||
| #define PyDateTime_TIME_GET_HOUR(o)        (((PyDateTime_Time*)o)->data[0]) | #define PyDateTime_TIME_GET_HOUR(o)        (((PyDateTime_Time*)o)->data[0]) | ||||||
| #define PyDateTime_TIME_GET_MINUTE(o)      (((PyDateTime_Time*)o)->data[1]) | #define PyDateTime_TIME_GET_MINUTE(o)      (((PyDateTime_Time*)o)->data[1]) | ||||||
| #define PyDateTime_TIME_GET_SECOND(o)      (((PyDateTime_Time*)o)->data[2]) | #define PyDateTime_TIME_GET_SECOND(o)      (((PyDateTime_Time*)o)->data[2]) | ||||||
|  | @ -113,9 +121,6 @@ typedef struct | ||||||
| #define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType) | #define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType) | ||||||
| #define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType) | #define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType) | ||||||
| 
 | 
 | ||||||
| #define PyTimeTZ_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeTZType) |  | ||||||
| #define PyTimeTZ_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeTZType) |  | ||||||
| 
 |  | ||||||
| #define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType) | #define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType) | ||||||
| #define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType) | #define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1857,7 +1857,7 @@ def test_pickling(self): | ||||||
|         tinfo = PicklableFixedOffset(-300, 'cookie') |         tinfo = PicklableFixedOffset(-300, 'cookie') | ||||||
|         orig = self.theclass(5, 6, 7, tzinfo=tinfo) |         orig = self.theclass(5, 6, 7, tzinfo=tinfo) | ||||||
|         state = orig.__getstate__() |         state = orig.__getstate__() | ||||||
|         derived = self.theclass() |         derived = self.theclass(tzinfo=FixedOffset(0, "UTC", 0)) | ||||||
|         derived.__setstate__(state) |         derived.__setstate__(state) | ||||||
|         self.assertEqual(orig, derived) |         self.assertEqual(orig, derived) | ||||||
|         self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset)) |         self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset)) | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Peters
						Tim Peters