Changeset 815 for trunk/pg.py


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

PEP8 recommends not assigning lambda expressions

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.