Changeset 815


Ignore:
Timestamp:
Feb 3, 2016, 4:11:13 PM (4 years ago)
Author:
cito
Message:

PEP8 recommends not assigning lambda expressions

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/pg.py

    r814 r815  
    4040from collections import namedtuple
    4141from operator import itemgetter
     42from functools import partial
    4243from re import compile as regex
    4344from json import loads as jsondecode, dumps as jsonencode
     
    146147    from inspect import getargspec
    147148
    148     get_args = lambda func: getargspec(func).args
     149    def get_args(func):
     150        return getargspec(func).args
    149151else:
    150     get_args = lambda func: list(signature(func).parameters)
     152
     153    def get_args(func):
     154        return list(signature(func).parameters)
    151155
    152156try:
     
    455459            typ = simple_type('record')
    456460            guess = cls.guess_simple_type
    457             typ._get_attnames = lambda _self: AttrDict(
    458                 (str(n + 1), simple_type(guess(v)))
    459                 for n, v in enumerate(value))
     461            def get_attnames(self):
     462                return AttrDict((str(n + 1), simple_type(guess(v)))
     463                    for n, v in enumerate(value))
     464            typ._get_attnames = get_attnames
    460465            return typ
    461466
     
    884889        if not self.connection or not self._needs_connection(cast):
    885890            return cast
    886         connection = self.connection
    887         return lambda value: cast(value, connection=connection)
     891        return partial(cast, connection=self.connection)
    888892
    889893    def get(self, typ, default=None):
     
    955959        return '%Y-%m-%d'
    956960
    957     def create_array_cast(self, cast):
     961    def create_array_cast(self, basecast):
    958962        """Create an array typecast for the given base cast."""
    959         return lambda v: cast_array(v, cast)
     963        def cast(v):
     964            return cast_array(v, basecast)
     965        return cast
    960966
    961967    def create_record_cast(self, name, fields, casts):
    962968        """Create a named record typecast for the given fields and casts."""
    963969        record = namedtuple(name, fields)
    964         return lambda v: record(*cast_record(v, casts))
     970        def cast(v):
     971            return record(*cast_record(v, casts))
     972        return cast
    965973
    966974
  • trunk/pgdb.py

    r814 r815  
    7373from math import isnan, isinf
    7474from collections import namedtuple
     75from functools import partial
    7576from re import compile as regex
    7677from json import loads as jsondecode, dumps as jsonencode
     
    117118    from inspect import getargspec
    118119
    119     get_args = lambda func: getargspec(func).args
     120    def get_args(func):
     121        return getargspec(func).args
    120122else:
    121     get_args = lambda func: list(signature(func).parameters)
     123
     124    def get_args(func):
     125        return list(signature(func).parameters)
    122126
    123127try:
     
    432436        if not self.connection or not self._needs_connection(cast):
    433437            return cast
    434         connection = self.connection
    435         return lambda value: cast(value, connection=connection)
     438        return partial(cast, connection=self.connection)
    436439
    437440    def get(self, typ, default=None):
     
    480483                    self.pop('_%s' % t, None)
    481484
    482     def create_array_cast(self, cast):
     485    def create_array_cast(self, basecast):
    483486        """Create an array typecast for the given base cast."""
    484         return lambda v: cast_array(v, cast)
     487        def cast(v):
     488            return cast_array(v, basecast)
     489        return cast
    485490
    486491    def create_record_cast(self, name, fields, casts):
    487492        """Create a named record typecast for the given fields and casts."""
    488493        record = namedtuple(name, fields)
    489         return lambda v: record(*cast_record(v, casts))
     494        def cast(v):
     495            return record(*cast_record(v, casts))
     496        return cast
    490497
    491498
Note: See TracChangeset for help on using the changeset viewer.