mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-30 23:37:29 +03:00 
			
		
		
		
	Fixed TYPE adaptation to basic tuples
Tuples and namedtuples have different constructors.
This commit is contained in:
		
							parent
							
								
									3cc8719998
								
							
						
					
					
						commit
						68305a0eb6
					
				|  | @ -765,7 +765,7 @@ class CompositeCaster(object): | ||||||
| 
 | 
 | ||||||
|         self.attnames = [ a[0] for a in attrs ] |         self.attnames = [ a[0] for a in attrs ] | ||||||
|         self.atttypes = [ a[1] for a in attrs ] |         self.atttypes = [ a[1] for a in attrs ] | ||||||
|         self.type = self._create_type(name, self.attnames) |         self._create_type(name, self.attnames) | ||||||
|         self.typecaster = _ext.new_type((oid,), name, self.parse) |         self.typecaster = _ext.new_type((oid,), name, self.parse) | ||||||
| 
 | 
 | ||||||
|     def parse(self, s, curs): |     def parse(self, s, curs): | ||||||
|  | @ -780,7 +780,7 @@ class CompositeCaster(object): | ||||||
| 
 | 
 | ||||||
|         attrs = [ curs.cast(oid, token) |         attrs = [ curs.cast(oid, token) | ||||||
|             for oid, token in zip(self.atttypes, tokens) ] |             for oid, token in zip(self.atttypes, tokens) ] | ||||||
|         return self.type(*attrs) |         return self._ctor(*attrs) | ||||||
| 
 | 
 | ||||||
|     _re_tokenize = regex.compile(r""" |     _re_tokenize = regex.compile(r""" | ||||||
|   \(? ([,\)])                       # an empty token, representing NULL |   \(? ([,\)])                       # an empty token, representing NULL | ||||||
|  | @ -809,9 +809,11 @@ class CompositeCaster(object): | ||||||
|         try: |         try: | ||||||
|             from collections import namedtuple |             from collections import namedtuple | ||||||
|         except ImportError: |         except ImportError: | ||||||
|             return tuple |             self.type = tuple | ||||||
|  |             self._ctor = lambda *args: tuple(args) | ||||||
|         else: |         else: | ||||||
|             return namedtuple(name, attnames) |             self.type = namedtuple(name, attnames) | ||||||
|  |             self._ctor = self.type | ||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     def _from_db(self, name, conn_or_curs): |     def _from_db(self, name, conn_or_curs): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user