python类LambdaType()的实例源码

testing.py 文件源码 项目:modern-paste 作者: LINKIWI 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def random_or_specified_value(cls, value):
        """
        Helper utility for choosing between a user-specified value for a field or a randomly generated value.

        :param value: Either a lambda type or a non-lambda type.
        :return: The value itself if not a lambda type, otherwise the value of the evaluated lambda (random value)
        """
        return value() if isinstance(value, types.LambdaType) else value
augmentations.py 文件源码 项目:textobjdetection 作者: andfoy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd
flow_transforms.py 文件源码 项目:FlowNetPytorch 作者: ClementPinard 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd
augmentations.py 文件源码 项目:realtime-action-detection 作者: gurkirt 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd
xml_types.py 文件源码 项目:rllabplusplus 作者: shaneshixiang 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _extract_type(typ):
    if isinstance(typ, LambdaType):
        return typ()
    else:
        return typ
schema.py 文件源码 项目:mimesis 作者: lk-geimfari 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, schema: LambdaType) -> None:
        if callable(schema) and isinstance(schema, LambdaType):
            self.schema = schema
        else:
            raise UndefinedSchema()
CallTips.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_argspec(ob):
    """Get a string describing the arguments for the given object."""
    argspec = ""
    if ob is not None:
        if isinstance(ob, type):
            fob = _find_constructor(ob)
            if fob is None:
                fob = lambda: None
        elif isinstance(ob, types.MethodType):
            fob = ob.__func__
        else:
            fob = ob
        if isinstance(fob, (types.FunctionType, types.LambdaType)):
            argspec = inspect.formatargspec(*inspect.getfullargspec(fob))
            pat = re.compile('self\,?\s*')
            argspec = pat.sub("", argspec)
        doc = getattr(ob, "__doc__", "")
        if doc:
            doc = doc.lstrip()
            pos = doc.find("\n")
            if pos < 0 or pos > 70:
                pos = 70
            if argspec:
                argspec += "\n"
            argspec += doc[:pos]
    return argspec

#################################################
#
# Test code
#
topology.py 文件源码 项目:deep-learning-keras-projects 作者: jasmeetsb 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_config(self):
        if isinstance(self.mode, python_types.LambdaType):
            mode = func_dump(self.mode)
            mode_type = 'lambda'
        elif callable(self.mode):
            mode = self.mode.__name__
            mode_type = 'function'
        else:
            mode = self.mode
            mode_type = 'raw'

        if isinstance(self._output_shape, python_types.LambdaType):
            output_shape = func_dump(self._output_shape)
            output_shape_type = 'lambda'
        elif callable(self._output_shape):
            output_shape = self._output_shape.__name__
            output_shape_type = 'function'
        else:
            output_shape = self._output_shape
            output_shape_type = 'raw'

        if isinstance(self._output_mask, python_types.LambdaType):
            output_mask = func_dump(self._output_mask)
            output_mask_type = 'lambda'
        elif callable(self._output_mask):
            output_mask = self._output_mask.__name__
            output_mask_type = 'function'
        else:
            output_mask = self._output_mask
            output_mask_type = 'raw'

        return {'name': self.name,
                'mode': mode,
                'mode_type': mode_type,
                'concat_axis': self.concat_axis,
                'dot_axes': self.dot_axes,
                'output_shape': output_shape,
                'output_shape_type': output_shape_type,
                'output_mask': output_mask,
                'output_mask_type': output_mask_type,
                'arguments': self.arguments}
flow_transforms.py 文件源码 项目:depth-semantic-fully-conv 作者: iapatil 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert type(lambd) is types.LambdaType
        self.lambd = lambd
turtle.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def getmethparlist(ob):
    "Get strings describing the arguments for the given object"
    argText1 = argText2 = ""
    # bit of a hack for methods - turn it into a function
    # but we drop the "self" param.
    if type(ob)==types.MethodType:
        fob = ob.im_func
        argOffset = 1
    else:
        fob = ob
        argOffset = 0
    # Try and build one for Python defined functions
    if type(fob) in [types.FunctionType, types.LambdaType]:
        try:
            counter = fob.func_code.co_argcount
            items2 = list(fob.func_code.co_varnames[argOffset:counter])
            realArgs = fob.func_code.co_varnames[argOffset:counter]
            defaults = fob.func_defaults or []
            defaults = list(map(lambda name: "=%s" % repr(name), defaults))
            defaults = [""] * (len(realArgs)-len(defaults)) + defaults
            items1 = map(lambda arg, dflt: arg+dflt, realArgs, defaults)
            if fob.func_code.co_flags & 0x4:
                items1.append("*"+fob.func_code.co_varnames[counter])
                items2.append("*"+fob.func_code.co_varnames[counter])
                counter += 1
            if fob.func_code.co_flags & 0x8:
                items1.append("**"+fob.func_code.co_varnames[counter])
                items2.append("**"+fob.func_code.co_varnames[counter])
            argText1 = ", ".join(items1)
            argText1 = "(%s)" % argText1
            argText2 = ", ".join(items2)
            argText2 = "(%s)" % argText2
        except:
            pass
    return argText1, argText2
turtle.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def getmethparlist(ob):
    "Get strings describing the arguments for the given object"
    argText1 = argText2 = ""
    # bit of a hack for methods - turn it into a function
    # but we drop the "self" param.
    if type(ob)==types.MethodType:
        fob = ob.im_func
        argOffset = 1
    else:
        fob = ob
        argOffset = 0
    # Try and build one for Python defined functions
    if type(fob) in [types.FunctionType, types.LambdaType]:
        try:
            counter = fob.func_code.co_argcount
            items2 = list(fob.func_code.co_varnames[argOffset:counter])
            realArgs = fob.func_code.co_varnames[argOffset:counter]
            defaults = fob.func_defaults or []
            defaults = list(map(lambda name: "=%s" % repr(name), defaults))
            defaults = [""] * (len(realArgs)-len(defaults)) + defaults
            items1 = map(lambda arg, dflt: arg+dflt, realArgs, defaults)
            if fob.func_code.co_flags & 0x4:
                items1.append("*"+fob.func_code.co_varnames[counter])
                items2.append("*"+fob.func_code.co_varnames[counter])
                counter += 1
            if fob.func_code.co_flags & 0x8:
                items1.append("**"+fob.func_code.co_varnames[counter])
                items2.append("**"+fob.func_code.co_varnames[counter])
            argText1 = ", ".join(items1)
            argText1 = "(%s)" % argText1
            argText2 = ", ".join(items2)
            argText2 = "(%s)" % argText2
        except:
            pass
    return argText1, argText2
data_augmentation.py 文件源码 项目:single_shot_multibox_detector 作者: oarriaga 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd
tf-keras-skeleton.py 文件源码 项目:LIE 作者: EmbraceLife 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_config(self):
            if isinstance(self.function, python_types.LambdaType):
              function = func_dump(self.function)
              function_type = 'lambda'
            else:
              function = self.function.__name__
              function_type = 'function'

            config = {
                'function': function,
                'function_type': function_type,
                'arguments': self.arguments
            }
            base_config = super(Lambda, self).get_config()
            return dict(list(base_config.items()) + list(config.items()))
view.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def getSubview(self, request, node, model, viewName):
        """Get a sub-view from me.

        @returns: L{widgets.Widget}
        """
        view = None
        vm = getattr(self, 'wvfactory_' + viewName, None)
        if vm is None:
            vm = getattr(self, 'factory_' + viewName, None)
            if vm is not None:
                warnings.warn("factory_ methods are deprecated; please use "
                              "wvfactory_ instead", DeprecationWarning)
        if vm:
            if vm.func_code.co_argcount == 3 and not type(vm) == types.LambdaType:
                 warnings.warn("wvfactory_ methods take (request, node, "
                               "model) instead of (request, node) now. \n"
                               "Please instantiate your widgets with a "
                               "reference to model instead of self.model",
                               DeprecationWarning)
                 self.model = model
                 view = vm(request, node)
                 self.model = self.mainModel
            else:
                view = vm(request, node, model)

        setupMethod = getattr(self, 'wvupdate_' + viewName, None)
        if setupMethod:
            if view is None:
                view = widgets.Widget(model)
            view.setupMethods.append(setupMethod)
        return view
assertion.py 文件源码 项目:QTAF 作者: Tencent 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def isFunType(obj):
    '''??obj????????lambda??
    '''
    return isinstance(obj,types.MethodType) or isinstance(obj,types.LambdaType)
assertion.py 文件源码 项目:QTAF 作者: Tencent 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _getFuncResult(func,args):
    '''?????????????????????????
    '''
    if not isinstance(func,types.MethodType) and not isinstance(func,types.LambdaType):
        raise TypeError("func type %s is not a MethodType or LambdaType" % type(func))
    if dict == type(args):
        actret = func(**args)
    elif tuple == type(args):
        actret = func(*args)
    else:
        actret = func(args)
    return actret
assertion.py 文件源码 项目:QTAF 作者: Tencent 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _waitForCompareResult(func,args,compareobj,timeout=10,interval=0.5):
    ''' ????????

       :param actualfunc: ??????????
       :param actargs: ???????????
       :param compareobj: ??????????????????????
       :return comparefunc: True or False
       :param timeout: ????
       :param interval: ??????
       :return type: tuple,(True,try_count,actual,expect)
    '''
    start = time.time()
    waited = 0.0
    try_count = 0
    while True:
        try_count +=1
        actret = _getFuncResult(func,args)
        if isinstance(compareobj,types.MethodType) or isinstance(compareobj,types.LambdaType):
            expret = _getFuncResult(compareobj,actret)
            if expret == True:
                return True,try_count,actret,expret
        else:
            expret = compareobj
            if actret == expret:
                return True,try_count,actret,expret
        waited = time.time() - start
        if waited < timeout:
            time.sleep(min(interval, timeout - waited))
        else:
            return False,try_count,actret,expret
augmentations.py 文件源码 项目:yolov2 作者: zhangkaij 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd
video_transforms.py 文件源码 项目:two-stream-pytorch 作者: bryanyzhu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, lambd):
        assert type(lambd) is types.LambdaType
        self.lambd = lambd
topology.py 文件源码 项目:keras-customized 作者: ambrite 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_config(self):
        if isinstance(self.mode, python_types.LambdaType):
            mode = func_dump(self.mode)
            mode_type = 'lambda'
        elif callable(self.mode):
            mode = self.mode.__name__
            mode_type = 'function'
        else:
            mode = self.mode
            mode_type = 'raw'

        if isinstance(self._output_shape, python_types.LambdaType):
            output_shape = func_dump(self._output_shape)
            output_shape_type = 'lambda'
        elif callable(self._output_shape):
            output_shape = self._output_shape.__name__
            output_shape_type = 'function'
        else:
            output_shape = self._output_shape
            output_shape_type = 'raw'

        if isinstance(self._output_mask, python_types.LambdaType):
            output_mask = func_dump(self._output_mask)
            output_mask_type = 'lambda'
        elif callable(self._output_mask):
            output_mask = self._output_mask.__name__
            output_mask_type = 'function'
        else:
            output_mask = self._output_mask
            output_mask_type = 'raw'

        return {'name': self.name,
                'mode': mode,
                'mode_type': mode_type,
                'concat_axis': self.concat_axis,
                'dot_axes': self.dot_axes,
                'output_shape': output_shape,
                'output_shape_type': output_shape_type,
                'output_mask': output_mask,
                'output_mask_type': output_mask_type,
                'arguments': self.arguments}


问题


面经


文章

微信
公众号

扫码关注公众号