Author: cito
Date: Wed Feb  3 16:11:13 2016
New Revision: 815

Log:
PEP8 recommends not assigning lambda expressions

Modified:
   trunk/pg.py
   trunk/pgdb.py

Modified: trunk/pg.py
==============================================================================
--- trunk/pg.py Wed Feb  3 15:23:20 2016        (r814)
+++ trunk/pg.py Wed Feb  3 16:11:13 2016        (r815)
@@ -39,6 +39,7 @@
 from math import isnan, isinf
 from collections import namedtuple
 from operator import itemgetter
+from functools import partial
 from re import compile as regex
 from json import loads as jsondecode, dumps as jsonencode
 
@@ -145,9 +146,12 @@
 except ImportError:  # Python < 3.3
     from inspect import getargspec
 
-    get_args = lambda func: getargspec(func).args
+    def get_args(func):
+        return getargspec(func).args
 else:
-    get_args = lambda func: list(signature(func).parameters)
+
+    def get_args(func):
+        return list(signature(func).parameters)
 
 try:
     if datetime.strptime('+0100', '%z') is None:
@@ -454,9 +458,10 @@
             simple_type = cls.simple_type
             typ = simple_type('record')
             guess = cls.guess_simple_type
-            typ._get_attnames = lambda _self: AttrDict(
-                (str(n + 1), simple_type(guess(v)))
-                for n, v in enumerate(value))
+            def get_attnames(self):
+                return AttrDict((str(n + 1), simple_type(guess(v)))
+                    for n, v in enumerate(value))
+            typ._get_attnames = get_attnames
             return typ
 
     @classmethod
@@ -883,8 +888,7 @@
         """Add a connection argument to the typecast function if necessary."""
         if not self.connection or not self._needs_connection(cast):
             return cast
-        connection = self.connection
-        return lambda value: cast(value, connection=connection)
+        return partial(cast, connection=self.connection)
 
     def get(self, typ, default=None):
         """Get the typecast function for the given database type."""
@@ -954,14 +958,18 @@
         """
         return '%Y-%m-%d'
 
-    def create_array_cast(self, cast):
+    def create_array_cast(self, basecast):
         """Create an array typecast for the given base cast."""
-        return lambda v: cast_array(v, cast)
+        def cast(v):
+            return cast_array(v, basecast)
+        return cast
 
     def create_record_cast(self, name, fields, casts):
         """Create a named record typecast for the given fields and casts."""
         record = namedtuple(name, fields)
-        return lambda v: record(*cast_record(v, casts))
+        def cast(v):
+            return record(*cast_record(v, casts))
+        return cast
 
 
 def get_typecast(typ):

Modified: trunk/pgdb.py
==============================================================================
--- trunk/pgdb.py       Wed Feb  3 15:23:20 2016        (r814)
+++ trunk/pgdb.py       Wed Feb  3 16:11:13 2016        (r815)
@@ -72,6 +72,7 @@
 from decimal import Decimal
 from math import isnan, isinf
 from collections import namedtuple
+from functools import partial
 from re import compile as regex
 from json import loads as jsondecode, dumps as jsonencode
 
@@ -116,9 +117,12 @@
 except ImportError:  # Python < 3.3
     from inspect import getargspec
 
-    get_args = lambda func: getargspec(func).args
+    def get_args(func):
+        return getargspec(func).args
 else:
-    get_args = lambda func: list(signature(func).parameters)
+
+    def get_args(func):
+        return list(signature(func).parameters)
 
 try:
     if datetime.strptime('+0100', '%z') is None:
@@ -431,8 +435,7 @@
         """Add a connection argument to the typecast function if necessary."""
         if not self.connection or not self._needs_connection(cast):
             return cast
-        connection = self.connection
-        return lambda value: cast(value, connection=connection)
+        return partial(cast, connection=self.connection)
 
     def get(self, typ, default=None):
         """Get the typecast function for the given database type."""
@@ -479,14 +482,18 @@
                     self.pop(t, None)
                     self.pop('_%s' % t, None)
 
-    def create_array_cast(self, cast):
+    def create_array_cast(self, basecast):
         """Create an array typecast for the given base cast."""
-        return lambda v: cast_array(v, cast)
+        def cast(v):
+            return cast_array(v, basecast)
+        return cast
 
     def create_record_cast(self, name, fields, casts):
         """Create a named record typecast for the given fields and casts."""
         record = namedtuple(name, fields)
-        return lambda v: record(*cast_record(v, casts))
+        def cast(v):
+            return record(*cast_record(v, casts))
+        return cast
 
 
 _typecasts = Typecasts()  # this is the global typecast dictionary
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to