當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。