class _ConfigDictOptional(tx.TypedDict, total=False): thirdparty: tx.TypedDict( "_ThirdpartyConfigDict", { "xxx": tx.TypedDict("_XXXConfigDict", {"token": str}), "zzz": tx.TypedDict( "_ZZZConfigDict", {"clientId": str, "clientSecret": str} ), }, )
def test_incorrect_return_http_code( return_code: t.Type[t.Any], mocker: ptm.MockFixture, ) -> None: test_returns = te.TypedDict( # type: ignore f'ReturnWithCodeAs_{return_code}', {'http_code': return_code}, ) async def test() -> test_returns: ... with pytest.raises(handler.InvalidHandlerError) as err: handler._resolve( handler=test, operation=_make_operation({ '204': { 'description': 'Incorrect return type', }, }), request_processor=mocker.Mock(), response_processor=mocker.Mock(), ) assert err assert err.value assert 1 == len(err.value)
def sync_recarm(self) -> None: """Synchronize recarm state of all childs with target childs. Raises ------ SessionError If no childs matched to slave. """ if self.target is None: raise SessionError(f'no target for track {self.name} ({self})') if not self._childs_matched_primary: raise SessionError(f'no matched childs for {self.name} ({self})') childs = self._return_matched_childs(TrackChildsSet.both) t_host = self.s_project.last_ip Targets = te.TypedDict('Targets', {'target': Track, 'recarm': bool}) with rpr.inside_reaper(): targets: ty.Dict[Track.ID, Targets] = {} for child in childs.values(): recarm = child.recarm assert child.target, f'no target for child: {child}' target = child.target if target.id not in targets: targets[target.id] = {'target': target, 'recarm': recarm} elif recarm is True: targets[target.id]['recarm'] = True with rpr.connect(t_host): with rpr.inside_reaper(): # with self.target.make_current_project(): for t_dict in targets.values(): target = t_dict['target'] recarm = t_dict['recarm'] target.recarm = recarm
def test_omitted_return_code_couple_oas_resp(mocker: ptm.MockFixture) -> None: test_returns = te.TypedDict( # type: ignore 'MissingHttpCode', {'body': t.Dict[str, int]}, ) async def test() -> test_returns: ... with pytest.raises(handler.InvalidHandlerError) as err: handler._resolve( handler=test, operation=_make_operation({ '200': { 'description': 'I am alone', }, '300': { 'description': 'I am alone', }, }), request_processor=mocker.Mock(), response_processor=mocker.Mock(), ) assert err assert err.value assert 1 == len(err.value) assert 'return.http_code' in err.value assert 'missing' == err.value['return.http_code']
def test_incorrect_cookies_type( cookies_type: t.Type[t.Any], mocker: ptm.MockFixture, ) -> None: test_returns = te.TypedDict( # type: ignore 'RV_Bad_Cookies', { 'http_code': int, 'cookies': cookies_type }, # type: ignore ) async def test() -> test_returns: ... with pytest.raises(handler.InvalidHandlerError) as err: handler._resolve( handler=test, operation=_make_operation({ '204': { 'description': 'Incorrect return type', }, }), request_processor=mocker.Mock(), response_processor=mocker.Mock(), ) assert err assert err.value assert 1 == len(err.value) assert 'return.cookies' in err.value assert (f'expected [' f'typing.Mapping[str, typing.Any],' f'typing.Dict[str, typing.Any],' f'typing_extensions.TypedDict], ' f'but got ' f'{get_type_repr.get_repr(cookies_type)}' ) == err.value['return.cookies']
def test_omitted_return_code_single_oas_resp( response_code: t.Union[str, te.Literal['default']], mocker: ptm.MockFixture, ) -> None: test_returns = te.TypedDict( # type: ignore 'MissingHttpCode', {'body': t.Dict[str, int]}, ) async def test() -> test_returns: ... handler._resolve( handler=test, operation=_make_operation({ f'{response_code}': { 'description': 'I am alone', }, }), request_processor=mocker.Mock(), response_processor=mocker.Mock(), )
import random import typing import numpy as np import albumentations as A import typing_extensions as tx BboxParams = A.BboxParams(format="pascal_voc", label_fields=["categories"]) AugmentedResult = tx.TypedDict( "AugmentedResult", { "image": np.ndarray, "bboxes": typing.List[typing.Tuple[int, int, int, int]], "categories": typing.List[str], }, ) # pylint: disable=too-few-public-methods class AugmenterProtocol(tx.Protocol): """A protocol defining how we expect augmentation pipelines to behave. bboxes is expected to be in pascal_voc (or x1, y1, x2, y2) format.""" def __call__( self, image: np.ndarray, bboxes: typing.List[typing.Tuple[int, int, int, int]], categories: typing.List[str], ) -> AugmentedResult:
return self._server.at_exit() def uptade_gui(self) -> None: send_data('gui_update', self.update_gui_info(), host=DEF_HOST, port=GUI_PORT) def update_gui_info(self) -> ty.Dict[str, ty.List[str]]: return {'slaves': self._slaves.active_slaves_list()} T_slave_servers = ty.List[ipy.IP] T_SlaveProject = te.TypedDict('T_SlaveProject', { 'ip': ipy.IP, 'name': str, 'connection_status': bool, }) T_slave_projects = ty.List[T_SlaveProject] class T_tracked_track_direction(Enum): to_slave = object() to_master = object() class T_tracked_track_type(Enum): midi = 'midi' audio = 'audio'
actual_result = axion_types.is_any_type(the_type) assert expected_result == actual_result @pytest.mark.parametrize('the_type', axion_types.P_TYPES) def test_is_not_any_type(the_type: t.Any) -> None: assert not axion_types.is_any_type(the_type) @pytest.mark.parametrize( 'the_type,expected_result', ( (t.Mapping[str, str], True), (t.Dict[str, str], True), (t.Mapping[int, float], True), (te.TypedDict('Z', z=int), True), # type: ignore (t.List[int], False), (int, False), (bool, False), (complex, False), (t.Set[int], False), (t.Dict[str, complex], True), ( types.new_class('C1', (t.Dict[str, str], )), True, ), ( types.new_class('C2', (t.Dict[t.Any, complex], )), True, ), (
return LEDGER_ENTRY_TYPES_BY_CODE[type_code] def deserialize_object(scanner: Scanner) -> t.Mapping: object_ = {} while scanner.peek(1) != OBJECT_END_MARKER: key, value = deserialize_field(scanner) object_[key] = value scanner.skip(1) return object_ Step = tex.TypedDict('Step', { 'account': Address, 'currency': str, 'issuer': Address, 'type': int, 'type_hex': str, }, total=False) Path = t.Collection[Step] PathSet = t.Collection[Path] def deserialize_path(scanner: Scanner) -> Path: path = [] while scanner.peek(1) not in (PATH_END_MARKER, PATHSET_END_MARKER): path.append(deserialize_step(scanner)) if scanner.peek(1) == PATH_END_MARKER: scanner.skip(1) return path
import typing import warnings import tensorflow as tf import typing_extensions as tx from . import layers, utils ConfigDict = tx.TypedDict( "ConfigDict", { "dropout": float, "mlp_dim": int, "num_heads": int, "num_layers": int, "hidden_size": int, }, ) CONFIG_B: ConfigDict = { "dropout": 0.1, "mlp_dim": 3072, "num_heads": 12, "num_layers": 12, "hidden_size": 768, } CONFIG_L: ConfigDict = { "dropout": 0.1, "mlp_dim": 4096, "num_heads": 16, "num_layers": 24,
# 32 bytes. PrivateKey = t.NewType('PrivateKey', bytes) # 33 bytes. PublicKey = t.NewType('PublicKey', bytes) # 20 bytes computed from a public key. AccountId = t.NewType('AccountId', bytes) # Base58 encoding (with prefix and checksum) of an account ID. # https://xrpl.org/accounts.html#address-encoding Address = t.NewType('Address', str) Signature = t.NewType('Signature', bytes) NonXrpAmount = tex.TypedDict('NonXrpAmount', { 'value': str, 'currency': str, 'issuer': str, }) XrpAmount = str Amount = t.Union[XrpAmount, NonXrpAmount] # TODO: TypedDict instead of Mapping. Transaction = t.Mapping SignedTransaction = t.Mapping DigestLike = t.Union[str, bytes] def to_digest(digest_like: DigestLike) -> bytes:
import reapy as rpr import typing as ty import typing_extensions as te import json import os from reasession.config import EXT_SECTION MidiBuf = te.TypedDict('MidiBuf', { 'qn': float, 'bus': int, 'buf': ty.List[int], }) MidiNote = te.TypedDict('MidiNote', { 'start': float, 'end': float, 'note': int, 'channel': int, 'velocity': int }) RenderSettings = te.TypedDict('RenderSettings', { 'value': ty.Dict[str, float], 'string': ty.Dict[str, str] }) class MidiRenderer: """Renders midi and can past it to different tracks (and hosts). Note ----
(t.Mapping, 'typing.Mapping[typing.Any, typing.Any]'), (t.Mapping[str, str], 'typing.Mapping[str, str]'), (t.Mapping[str, int], 'typing.Mapping[str, int]'), (t.Mapping[int, str], 'typing.Mapping[int, str]'), (t.AbstractSet, 'typing.AbstractSet[typing.Any]'), (t.AbstractSet[bool], 'typing.AbstractSet[bool]'), (t.Optional[t.AbstractSet[bool]], 'typing.Optional[typing.AbstractSet[bool]]'), (type(None), 'NoneType'), (None, None), (t.Any, 'typing.Any'), (te.TypedDict, 'typing_extensions.TypedDict'), ( te.TypedDict( # type: ignore 'Cookies', { 'debug': bool, 'csrftoken': str, }, ), 'Cookies{csrftoken: str, debug: bool}', ), ( te.TypedDict( # type: ignore 'Paging', { 'page': t.Optional[int], 'hasNext': bool, 'hasPrev': bool, }, ), 'Paging{hasNext: bool, hasPrev: bool, page: typing.Optional[int]}',
( response_code, return_type, ) for response_code in [ 200, 201, 204, 300, 401, 404, 500, 503, ] for return_type in ( pipeline.Response, te.TypedDict( # type: ignore 'JustHttpCodeIsOk', {'http_code': int}, ), te.TypedDict( # type: ignore 'JustHttpCodeIsAsNewType_Int', {'http_code': t.NewType('HTTP_CODE', int)}, ), te.TypedDict( # type: ignore 'HttpCodeWithSomeJunkThatWillBeIgnored', { 'http_code': int, 'foo': str, 'bar': bool, }, ), te.TypedDict( # type: ignore f'HttpCodeDefinedAs_Literal[{response_code}]',
import tempfile import numpy as np import typing_extensions as tx from . import files LOGGER = logging.getLogger(__name__) Target = tx.TypedDict( "Target", { "idx": int, "target": typing.Union[str, np.ndarray], "type": tx.Literal["video", "image"], "metadata": dict, "visible": bool, "selected": bool, "ignored": bool, "labeled": bool, "labels": dict, }, ) def deprecate(old, new): """Log a deprecation message.""" LOGGER.warning("%s has been deprecated. Use %s instead.", old, new) def merge_items(initial, insert): """Merge two lists of items if there is an
addr_t, auth_t, cookies_t, headers_t, params_t, reqdata_sync_t, timeout_t, Closable, ) if ty.TYPE_CHECKING: import httpx._types import typing_extensions # By using the precise types from HTTPx we'll also get type errors if our # types become somehow incompatible with the ones from that library RequestArgs = typing_extensions.TypedDict("RequestArgs", { "auth": "httpx._types.AuthTypes", "cookies": "httpx._types.CookieTypes", "headers": "httpx._types.HeaderTypes", "timeout": "httpx._types.TimeoutTypes", "params": "httpx._types.QueryParamTypes", }, total=False) else: RequestArgs = ty.Dict[str, ty.Any] def map_args_to_httpx( *, auth: auth_t = None, cookies: cookies_t = None, headers: headers_t = None, params: params_t = None, timeout: timeout_t = None, ) -> RequestArgs:
import typing import typing_extensions from bitstruct import CompiledFormatDict if typing.TYPE_CHECKING: import os import sys from cantools.database import Signal class Formats(typing.NamedTuple): big_endian: CompiledFormatDict little_endian: CompiledFormatDict padding_mask: int StringPathLike = typing.Union[str, "os.PathLike[str]"] Comments = typing.Dict[typing.Optional[str], str] Codec = typing_extensions.TypedDict( "Codec", { "signals": typing.List["Signal"], "formats": Formats, "multiplexers": typing.Dict[str, typing.Dict[int, typing.Any]], }, )
# https://wsgi.readthedocs.io/en/latest/definitions.html StandardEnviron = tx.TypedDict( "StandardEnviron", { # The HTTP request method, such as GET or POST. This cannot ever be an # empty string, and so is always required. "REQUEST_METHOD": str, # The remainder of the request URL’s “path”, designating the virtual # “location” of the request’s target within the application. This may be an # empty string, if the request URL targets the application root and does # not have a trailing slash. "PATH_INFO": str, # The initial portion of the request URL’s “path” that corresponds to the # application object, so that the application knows its virtual “location”. # This may be an empty string, if the application corresponds to the “root” # of the server. "SCRIPT_NAME": str, # The portion of the request URL that follows the “?”, if any. May be empty # or absent. "QUERY_STRING": t.Optional[str], # The contents of any Content-Type fields in the HTTP request. May be empty # or absent. "CONTENT_TYPE": t.Optional[str], }) WSGIEnviron = tx.TypedDict(
from . import common_types as ct GUI_DEBUG_MODE = os.getenv('SBK_GUI_DEBUG_MODE') == "1" logger = logging.getLogger("sbk.gui_panels") PanelState = typext.TypedDict( 'PanelState', { 'panel_index': int, 'salt': Optional[ct.Salt], 'brainkey': Optional[ct.BrainKey], 'shares': ct.Shares, 'params': Optional[parameters.Parameters], 'seed_data': Optional[ct.SeedData], # options 'sys_info': Optional[sys_info.SystemInfo], 'offline': bool, 'wallet_name': str, # 'sss_t' : int, # 'sss_n' : int, 'target_memory': int, 'target_duration': int, 'max_memory': int, }, ) shared_panel_state: PanelState = { 'panel_index': 0, 'salt': None, 'brainkey': None, 'shares': [],
"""Types for mypy type-checking """ import gzip import typing if typing.TYPE_CHECKING: import os import typing_extensions CanFilter = typing_extensions.TypedDict("CanFilter", { "can_id": int, "can_mask": int }) CanFilterExtended = typing_extensions.TypedDict("CanFilterExtended", { "can_id": int, "can_mask": int, "extended": bool }) CanFilters = typing.Sequence[typing.Union[CanFilter, CanFilterExtended]] # TODO: Once buffer protocol support lands in typing, we should switch to that, # since can.message.Message attempts to call bytearray() on the given data, so # this should have the same typing info. # # See: https://github.com/python/typing/issues/593 CanData = typing.Union[bytes, bytearray, int, typing.Iterable[int]] # Used for the Abstract Base Class ChannelStr = str ChannelInt = int
from transformers import EvalPrediction from transformers import InputFeatures # type: ignore from transformers import Trainer from transformers import TrainingArguments # type: ignore from transformers.tokenization_utils import PreTrainedTokenizer from transformers.trainer_utils import PredictionOutput from flask_app.modeling.lda import CSV_EXTENSIONS from flask_app.settings import Settings # Named as such to distinguish from db.ClassifierMetrics ClassifierMetricsJson = TT.TypedDict( "ClassifierMetricsJson", { "accuracy": float, "macro_f1_score": float, "macro_recall": float, "macro_precision": float, }, ) class ClassificationDataset(Dataset): # type: ignore """Inherits from Torch dataset. Loads and holds tokenized data for a BERT model.""" def __init__( self, labels: T.List[str], tokenizer: PreTrainedTokenizer, label_map: T.Dict[str, int], dset_filename: str, content_column: str,
import typing as t import typing_extensions as tx import sys import argparse import json _XXXConfigDict = tx.TypedDict("_XXXConfigDict", {"token": str}) _ZZZConfigDict = tx.TypedDict("_ZZZConfigDict", { "clientId": str, "clientSecret": str }) _MainConfigDict = tx.TypedDict("_MainConfigDict", {"db": str}) _ThirdpartyConfigDict = tx.TypedDict( "_ThirdpartyConfigDict", { "xxx": _XXXConfigDict, "zzz": _ZZZConfigDict, }, ) class _ConfigDictOptional(tx.TypedDict, total=False): thirdparty: _ThirdpartyConfigDict class ConfigDict(_ConfigDictOptional, total=True): main: _MainConfigDict def JSONDictType(filename_or_content: str,
response_processor=mocker.Mock(), ) assert id(hdrl.user_handler) == id(foo) assert not hdrl.cookie_params assert 'No "cookies" in signature and operation parameters' in caplog.messages @pytest.mark.parametrize( 'the_type', ( t.Mapping[str, str], t.Dict[str, str], te.TypedDict( # type: ignore 'Cookies', { 'debug': bool, 'csrftoken': str, }, ), ), ) def test_signature_set_no_oas_cookies( the_type: t.Type[t.Any], caplog: logging.LogCaptureFixture, mocker: ptm.MockFixture, ) -> None: async def foo(name: str, cookies: the_type) -> pipeline.Response: # type: ignore ... with pytest.raises(handler.InvalidHandlerError) as err: handler._resolve( foo,
import math import typing import logging from networkx.algorithms import approximation import typing_extensions import networkx as nx import numpy as np import faiss LOGGER = logging.getLogger(__name__) DEFAULT_PCT_PROBE = 0 ClusterAssignment = typing_extensions.TypedDict('ClusterAssignment', { 'cluster': int, 'id': str }) def build_index(X: np.ndarray, pct_probe: float = DEFAULT_PCT_PROBE, approximate=True): """Buid a FAISS index from a reference dataframe. Args: X: The vectors to add to the index. pct_probe: The minimum fraction of nearest lists to search. If the product of pct_probe and the number of lists is less than 1, one list will be searched. approximate: Whether to build an approximate or exact index.
import typing as t import typing_extensions as te IncludeFileArgs = te.TypedDict( "IncludeFileArgs", { "input_file": str, "start": t.Optional[int], "end": t.Optional[int], "indent": t.Optional[int], "section": t.Optional[str], "start_after": t.Optional[str], "end_before": t.Optional[str], }, ) def make_include_reg(prefix: str) -> str: return f"{prefix} " # "([^"]*)" ?(.*)$' def _split_args(args: str) -> t.List[str]: index = 0 result = [] while index < len(args): while len(args) > index and args[index] == " ": index += 1 if len(args) <= index: break
# pylint: disable=invalid-name,line-too-long,no-value-for-parameter,too-many-instance-attributes,too-many-locals,too-many-arguments,no-member import time import typing import warnings import typing_extensions import pandas as pd import numpy as np import faiss import perception.hashers.tools as pht QueryInput = typing_extensions.TypedDict('QueryInput', { 'id': str, 'hash': str }) QueryMatch = typing_extensions.TypedDict('QueryMatch', { 'id': typing.Any, 'matches': typing.List[dict] }) class TuningFailure(Exception): pass class QueryDecodingFailure(Exception): pass
This decorator allows one to react to a message on a google pub sub stream Methods with this decorator are expected to have a signature like the following:: @subhook(project='a-test-project', sub='a-test-sub') def a_webhook(self, message): message.ack() pass """ def wrapped_sub(func): return _tag_subhook(func, project, sub) return wrapped_sub PubSubConfig = te.TypedDict('PubSubConfig', {'SERVICE_ACCOUNT_JSON': typing.Optional[str]}) class Sub(): def __init__(self, project, sub, callback): self.project: str = project self.sub = sub self.callback = callback self.subscription_name = None self.result = None self.activated = False def __hash__(self): return self.callback.__hash__() def __eq__(self, other):
description: str default: t.Any properties: t.Dict[str, t.Union[PropertyDict, RefDict, OneOfDict]] required: t.List[str] additionalProperties: t.Union[bool, t.Dict[str, t.Any]] class OneOfDict(tx.TypedDict, total=False): # required oneOf: t.List[t.Union[RefDict, t.Dict[str, t.Any]]] # optional discriminator: t.Dict[str, str] # {PropertyName:str} RefDict = tx.TypedDict("RefDict", {"$ref": str}) class PropertyDict(tx.TypedDict, total=False): # required type: detect.JSONSchemaType # optional format: str default: t.Any description: str enum: t.Sequence[t.Any] # only type=array items: t.Union[RefDict, OneOfDict, t.Dict[str, t.Any]]
class ConfigDict(_ConfigDictOptional, total=True): main: tx.TypedDict("_MainConfigDict", {"db": str})