本文整理匯總了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'}
示例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)
)
示例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)
)
示例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)
示例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)
示例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)),
)
示例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)
示例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,
)
示例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)
示例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))
示例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.")
示例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)
)
示例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)
)
示例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)
)
示例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)