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


Python typing_extensions.Final方法代码示例

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


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

示例1: test_final_field

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def test_final_field():

    @dataclass
    class TestWithFinal(JsonSchemaMixin):
        """Dataclass with final field"""
        name: Final[str]

    expected_schema = {
        'type': 'object',
        'description': 'Dataclass with final field',
        'properties': {
            'name': {'type': 'string'}
        },
        'required': ['name']
    }

    assert TestWithFinal.json_schema() == compose_schema(expected_schema)
    assert TestWithFinal.from_dict({'name': 'foo'}) == TestWithFinal(name='foo')
    assert TestWithFinal(name='foo').to_dict() == {'name': 'foo'} 
开发者ID:s-knibbs,项目名称:dataclasses-jsonschema,代码行数:21,代码来源:test_core.py

示例2: sleep_get

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def sleep_get(
        self,
        startdate: Optional[DateType] = None,
        enddate: Optional[DateType] = None,
        data_fields: Optional[Iterable[GetSleepField]] = None,
    ) -> SleepGetResponse:
        """Get sleep data."""
        params: Final[ParamsType] = {}

        update_params(
            params, "startdate", startdate, lambda val: arrow.get(val).timestamp
        )
        update_params(params, "enddate", enddate, lambda val: arrow.get(val).timestamp)
        update_params(
            params,
            "data_fields",
            data_fields,
            lambda fields: ",".join([field.value for field in fields]),
        )
        update_params(params, "action", "get")

        return new_sleep_get_response(
            self.request(path=self.PATH_V2_SLEEP, params=params)
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:26,代码来源:__init__.py

示例3: notify_get

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def notify_get(
        self, callbackurl: str, appli: Optional[NotifyAppli] = None
    ) -> NotifyGetResponse:
        """
        Get subscription.

        Return the last notification service that a user was subscribed to,
        and its expiry date.
        """
        params: Final[ParamsType] = {}

        update_params(params, "callbackurl", callbackurl)
        update_params(params, "appli", appli, lambda appli: appli.value)
        update_params(params, "action", "get")

        return new_notify_get_response(
            self.request(path=self.PATH_NOTIFY, params=params)
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:20,代码来源:__init__.py

示例4: notify_revoke

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def notify_revoke(
        self, callbackurl: Optional[str] = None, appli: Optional[NotifyAppli] = None
    ) -> None:
        """
        Revoke a subscription.

        This service disables the notification between the API and the
        specified applications for the user.
        """
        params: Final[ParamsType] = {}

        update_params(params, "callbackurl", callbackurl)
        update_params(params, "appli", appli, lambda appli: appli.value)
        update_params(params, "action", "revoke")

        self.request(path=self.PATH_NOTIFY, params=params) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:18,代码来源:__init__.py

示例5: notify_update

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def notify_update(
        self,
        callbackurl: str,
        appli: NotifyAppli,
        new_callbackurl: str,
        new_appli: Optional[NotifyAppli] = None,
        comment: Optional[str] = None,
    ) -> None:
        """Update the callbackurl and or appli of a created notification."""
        params: Final[ParamsType] = {}

        update_params(params, "callbackurl", callbackurl)
        update_params(params, "appli", appli, lambda appli: appli.value)
        update_params(params, "new_callbackurl", new_callbackurl)
        update_params(params, "new_appli", new_appli, lambda new_appli: new_appli.value)
        update_params(params, "comment", comment)
        update_params(params, "action", "update")

        self.request(path=self.PATH_NOTIFY, params=params) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:21,代码来源:__init__.py

示例6: __init__

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def __init__(
        self,
        client_id: str,
        consumer_secret: str,
        callback_uri: str,
        scope: Iterable[AuthScope] = tuple(),
        mode: Optional[str] = None,
    ):
        """Initialize new object."""
        self._client_id: Final = client_id
        self._consumer_secret: Final = consumer_secret
        self._callback_uri: Final = callback_uri
        self._scope: Final = scope
        self._mode: Final = mode
        self._session: Final = OAuth2Session(
            self._client_id,
            redirect_uri=self._callback_uri,
            scope=",".join((scope.value for scope in self._scope)),
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:21,代码来源:__init__.py

示例7: _flexible_tuple_of

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def _flexible_tuple_of(
    items: Iterable[Any], fun: Callable[[Any], GenericType]
) -> Tuple[GenericType, ...]:
    """Create a tuple of objects resolved through lambda.

    If the lambda throws an exception, the resulting item will be ignored.
    """
    new_items: Final[List[GenericType]] = []
    for item in items:
        try:
            new_items.append(fun(item))
        except Exception:  # pylint:disable=broad-except
            print(
                "Warning: Failed to convert object. See exception for details.",
                traceback.format_exc(),
            )

    return tuple(new_items) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:20,代码来源:common.py

示例8: get_measure_value

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def get_measure_value(
    from_source: Union[
        MeasureGetMeasGroup, MeasureGetMeasResponse, Tuple[MeasureGetMeasGroup, ...]
    ],
    with_measure_type: Union[MeasureType, Tuple[MeasureType, ...]],
    with_group_attrib: Union[
        MeasureGetMeasGroupAttrib, Tuple[MeasureGetMeasGroupAttrib, ...]
    ] = MeasureGroupAttribs.ANY,
) -> Optional[float]:
    """Get the first value of a measure that meet the query requirements."""
    groups: Final = query_measure_groups(
        from_source, with_measure_type, with_group_attrib
    )

    return next(
        iter(
            tuple(
                float(measure.value * pow(10, measure.unit))
                for group in groups
                for measure in group.measures
            )
        ),
        None,
    ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:26,代码来源:common.py

示例9: response_body_or_raise

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def response_body_or_raise(data: Any) -> Dict[str, Any]:
    """Parse withings response or raise exception."""
    parsed_response: Final = dict_or_raise(data)
    status_any: Final = parsed_response.get("status")
    status: Final = int_or_none(status_any)

    if status is None:
        raise UnknownStatusException(status=status)
    if status in STATUS_SUCCESS:
        return cast(Dict[str, Any], parsed_response.get("body"))
    if status in STATUS_AUTH_FAILED:
        raise AuthFailedException(status=status)
    if status in STATUS_INVALID_PARAMS:
        raise InvalidParamsException(status=status)
    if status in STATUS_UNAUTHORIZED:
        raise UnauthorizedException(status=status)
    if status in STATUS_ERROR_OCCURRED:
        raise ErrorOccurredException(status=status)
    if status in STATUS_TIMEOUT:
        raise TimeoutException(status=status)
    if status in STATUS_BAD_STATE:
        raise BadStateException(status=status)
    if status in STATUS_TOO_MANY_REQUESTS:
        raise TooManyRequestsException(status=status)
    raise UnknownStatusException(status=status) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:27,代码来源:common.py

示例10: _is_parametrized_type_hint

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def _is_parametrized_type_hint(obj):
        # This is very cheap but might generate false positives.
        # general typing Constructs
        is_typing = getattr(obj, '__origin__', None) is not None

        # typing_extensions.Literal
        is_litteral = getattr(obj, '__values__', None) is not None

        # typing_extensions.Final
        is_final = getattr(obj, '__type__', None) is not None

        # typing.Union/Tuple for old Python 3.5
        is_union = getattr(obj, '__union_params__', None) is not None
        is_tuple = getattr(obj, '__tuple_params__', None) is not None
        is_callable = (
            getattr(obj, '__result__', None) is not None and
            getattr(obj, '__args__', None) is not None
        )
        return any((is_typing, is_litteral, is_final, is_union, is_tuple,
                    is_callable)) 
开发者ID:ray-project,项目名称:ray,代码行数:22,代码来源:cloudpickle.py

示例11: delete_edit_timer

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def delete_edit_timer(
    msg: Any, time: int, error: bool = False, call_msg: Any = None
) -> None:
    """
    Counts down by editing the response message, then deletes both that one and
    the original message.
    """
    ws: Final = ":white_small_square:"
    bs: Final = ":black_small_square:"

    # Cache the message content. We can't use msg.content in the for
    # loop as the msg object is mutable (so that we would append a new
    # line for every loop iteration).
    msg_text: str = msg.content

    for i in range(time + 1):
        await msg.edit(content=msg_text + "\n" + ws * (time - i) + bs * i)
        await asyncio.sleep(1)

    await msg.delete()

    if call_msg:
        # Prevent crash if the call message has been deleted before the bot
        # gets to it.
        try:
            await call_msg.delete()
        except:
            print("Call message does not exist.") 
开发者ID:Calinou,项目名称:datcord_bot,代码行数:30,代码来源:main.py

示例12: measure_get_activity

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def measure_get_activity(
        self,
        startdateymd: Optional[DateType] = None,
        enddateymd: Optional[DateType] = None,
        offset: Optional[int] = None,
        data_fields: Optional[Iterable[GetActivityField]] = None,
        lastupdate: Optional[DateType] = None,
    ) -> MeasureGetActivityResponse:
        """Get user created activities."""
        params: Final[ParamsType] = {}

        update_params(
            params,
            "startdateymd",
            startdateymd,
            lambda val: arrow.get(val).format("YYYY-MM-DD"),
        )
        update_params(
            params,
            "enddateymd",
            enddateymd,
            lambda val: arrow.get(val).format("YYYY-MM-DD"),
        )
        update_params(params, "offset", offset)
        update_params(
            params,
            "data_fields",
            data_fields,
            lambda fields: ",".join([field.value for field in fields]),
        )
        update_params(
            params, "lastupdate", lastupdate, lambda val: arrow.get(val).timestamp
        )
        update_params(params, "action", "getactivity")

        return new_measure_get_activity_response(
            self.request(path=self.PATH_V2_MEASURE, params=params)
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:40,代码来源:__init__.py

示例13: measure_get_meas

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def measure_get_meas(
        self,
        meastype: Optional[MeasureType] = None,
        category: Optional[MeasureGetMeasGroupCategory] = None,
        startdate: Optional[DateType] = None,
        enddate: Optional[DateType] = None,
        offset: Optional[int] = None,
        lastupdate: Optional[DateType] = None,
    ) -> MeasureGetMeasResponse:
        """Get measures."""
        params: Final[ParamsType] = {}

        update_params(params, "meastype", meastype, lambda val: val.value)
        update_params(params, "category", category, lambda val: val.value)
        update_params(
            params, "startdate", startdate, lambda val: arrow.get(val).timestamp
        )
        update_params(params, "enddate", enddate, lambda val: arrow.get(val).timestamp)
        update_params(params, "offset", offset)
        update_params(
            params, "lastupdate", lastupdate, lambda val: arrow.get(val).timestamp
        )
        update_params(params, "action", "getmeas")

        return new_measure_get_meas_response(
            self.request(path=self.PATH_MEASURE, params=params)
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:29,代码来源:__init__.py

示例14: sleep_get_summary

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def sleep_get_summary(
        self,
        startdateymd: Optional[DateType] = None,
        enddateymd: Optional[DateType] = None,
        data_fields: Optional[Iterable[GetSleepSummaryField]] = None,
        lastupdate: Optional[DateType] = None,
    ) -> SleepGetSummaryResponse:
        """Get sleep summary."""
        params: Final[ParamsType] = {}

        update_params(
            params,
            "startdateymd",
            startdateymd,
            lambda val: arrow.get(val).format("YYYY-MM-DD"),
        )
        update_params(
            params,
            "enddateymd",
            enddateymd,
            lambda val: arrow.get(val).format("YYYY-MM-DD"),
        )
        update_params(
            params,
            "data_fields",
            data_fields,
            lambda fields: ",".join([field.value for field in fields]),
        )
        update_params(
            params, "lastupdate", lastupdate, lambda val: arrow.get(val).timestamp
        )
        update_params(params, "action", "getsummary")

        return new_sleep_get_summary_response(
            self.request(path=self.PATH_V2_SLEEP, params=params)
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:38,代码来源:__init__.py

示例15: notify_subscribe

# 需要导入模块: import typing_extensions [as 别名]
# 或者: from typing_extensions import Final [as 别名]
def notify_subscribe(
        self,
        callbackurl: str,
        appli: Optional[NotifyAppli] = None,
        comment: Optional[str] = None,
    ) -> None:
        """Subscribe to receive notifications when new data is available."""
        params: Final[ParamsType] = {}

        update_params(params, "callbackurl", callbackurl)
        update_params(params, "appli", appli, lambda appli: appli.value)
        update_params(params, "comment", comment)
        update_params(params, "action", "subscribe")

        self.request(path=self.PATH_NOTIFY, params=params) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:17,代码来源:__init__.py


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