当前位置: 首页>>代码示例>>Python>>正文


Python Parameter.POSITIONAL_ONLY属性代码示例

本文整理汇总了Python中inspect.Parameter.POSITIONAL_ONLY属性的典型用法代码示例。如果您正苦于以下问题:Python Parameter.POSITIONAL_ONLY属性的具体用法?Python Parameter.POSITIONAL_ONLY怎么用?Python Parameter.POSITIONAL_ONLY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在inspect.Parameter的用法示例。


在下文中一共展示了Parameter.POSITIONAL_ONLY属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getargspec

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def getargspec(func):
        signature = inspect.signature(func)

        args = []
        varargs = None
        keywords = None
        defaults = []

        for param in signature.parameters.values():  # type: Parameter
            if param.kind == Parameter.VAR_POSITIONAL:
                varargs = param.name
            elif param.kind in (
                    Parameter.POSITIONAL_ONLY,
                    Parameter.KEYWORD_ONLY,
                    Parameter.POSITIONAL_OR_KEYWORD):
                args.append(param.name)
            elif param.kind == Parameter.VAR_KEYWORD:
                keywords = param.name

            # noinspection PyProtectedMember
            if param.default is not inspect._empty:
                defaults.append(param.default)

        return ArgSpec(args, varargs, keywords, tuple(defaults)) 
开发者ID:Bahus,项目名称:easy_cache,代码行数:26,代码来源:compat.py

示例2: positional_arguments

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def positional_arguments(sig):
    return len([p for n, p in sig.parameters.items()
                if p.kind in (Parameter.POSITIONAL_ONLY,
                              Parameter.POSITIONAL_OR_KEYWORD)]) 
开发者ID:kaste,项目名称:mockito-python,代码行数:6,代码来源:signature.py

示例3: __init__

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def __init__(self, iface_name, method):
		self._iface_name = iface_name
		self.__name__ = method.attrib["name"]
		self.__qualname__ = self._iface_name + "." + self.__name__

		self._inargs  = [(arg.attrib.get("name", ""), arg.attrib["type"]) for arg in method if arg.tag == "arg" and arg.attrib.get("direction", "in") == "in"]
		self._outargs = [arg.attrib["type"] for arg in method if arg.tag == "arg" and arg.attrib.get("direction", "in") == "out"]
		self._sinargs  = "(" + "".join(x[1] for x in self._inargs) + ")"
		self._soutargs = "(" + "".join(self._outargs) + ")"

		self_param = Parameter("self", Parameter.POSITIONAL_ONLY)
		pos_params = []
		for i, a in enumerate(self._inargs):
			name = filter_identifier(a[0])

			if not name:
				name = "arg" + str(i)

			param = Parameter(name, Parameter.POSITIONAL_ONLY, annotation=a[1])

			pos_params.append(param)
		ret_type = Signature.empty if len(self._outargs) == 0 else self._outargs[0] if len(self._outargs) == 1 else "(" + ", ".join(self._outargs) + ")"

		self.__signature__ = DBUSSignature([self_param] + pos_params, return_annotation=ret_type)

		if put_signature_in_doc:
			self.__doc__ = self.__name__ + str(self.__signature__) 
开发者ID:LEW21,项目名称:pydbus,代码行数:29,代码来源:proxy_method.py

示例4: _convert_from_parameter_kind

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def _convert_from_parameter_kind(kind):
    if kind == Parameter.POSITIONAL_ONLY:
        return 0
    if kind == Parameter.POSITIONAL_OR_KEYWORD:
        return 1
    if kind == Parameter.VAR_POSITIONAL:
        return 2
    if kind == Parameter.KEYWORD_ONLY:
        return 3
    if kind == Parameter.VAR_KEYWORD:
        return 4 
开发者ID:ray-project,项目名称:ray,代码行数:13,代码来源:signature.py

示例5: _convert_to_parameter_kind

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def _convert_to_parameter_kind(value):
    if value == 0:
        return Parameter.POSITIONAL_ONLY
    if value == 1:
        return Parameter.POSITIONAL_OR_KEYWORD
    if value == 2:
        return Parameter.VAR_POSITIONAL
    if value == 3:
        return Parameter.KEYWORD_ONLY
    if value == 4:
        return Parameter.VAR_KEYWORD 
开发者ID:ray-project,项目名称:ray,代码行数:13,代码来源:signature.py

示例6: __callbacks_parameters

# 需要导入模块: from inspect import Parameter [as 别名]
# 或者: from inspect.Parameter import POSITIONAL_ONLY [as 别名]
def __callbacks_parameters(parameters: List[Parameter]) -> Tuple[list, dict]:
        # Given params
        ordered_params = []
        keyword_params = {}

        # Go through all params
        for param in parameters:
            # Basic param information
            has_default = (param.default != Parameter.empty)
            has_type = (param.annotation != Parameter.empty)
            param_type = str(param.annotation) if has_type else "Unknown"
            param_default = (", leave blank for default " + str(param.default)) if has_default else ""

            # Validate the parameter input
            given_param = False

            def valid(this):
                # Not started
                if this is None:
                    return False

                # Default?
                if this.strip() == "":
                    if has_default:
                        return param.default
                    return False

                # Normal
                try:
                    return param.annotation(this)
                except Exception:
                    return this

            # Get input
            while given_param is False:
                given_param = valid(input(
                    "[Callbacks Debug] Parameter '" + param.name + "' (expects " + param_type + param_default + "): "))

            # Add to return
            if param.kind == Parameter.POSITIONAL_ONLY:
                ordered_params.append(given_param)
            else:
                keyword_params[param.name] = given_param

        return ordered_params, keyword_params 
开发者ID:MattIPv4,项目名称:PyDMXControl,代码行数:47,代码来源:debug.py


注:本文中的inspect.Parameter.POSITIONAL_ONLY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。