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