def __init__(self, query_db: Callable[ [str, DefaultArg(Tuple ), DefaultArg(bool, 'one')], Row], store_db: Callable[[str, DefaultArg(Tuple)], int]): self.query_db = query_db self.store_db = store_db self.university = university.University(self.query_db) self.scraper = scraper.Scraper(get_webpage)
def __init__(self, query_db: Callable[[str, DefaultArg(Tuple), DefaultArg(bool, 'one')], Row]): # need to decide how degree/course details passed in # unpack and create degree.Degree and course.Course objects self.query_db = query_db self.course_requirement_types = self.load_course_requirement_types() self.course_filter_types = self.load_course_filter_types() # cache of courses loaded from the db for this session, indexed by database id self.courses: Dict[int, 'course.Course'] = {} # cache of degrees loaded from the db for this session, indexed by numeric code (which is # also db id) self.degrees: Dict[Tuple[str, int], 'degree.Degree'] = {}
def test__pass_args_to_function( function: Callable[[ DefaultArg(Any, 'arg0'), DefaultArg(Any, 'arg1'), DefaultArg(Any, 'arg2'), ], None] ) -> None: """Test passing argument to functions decorated by `@pass_args`.""" function() function("a") function("a", "b") function(arg1="b") function(arg2="c") function(arg0="a", arg1="b") function(arg0="a", arg1="b", arg2="c")
WAIT_DELETE_S = 5 BounceMethodResult = TypedDict( 'BounceMethodResult', { "create_app": bool, "tasks_to_drain": Set, }, ) BounceMethod = Callable[[ Arg(BounceMethodConfigDict, 'new_config'), Arg(bool, 'new_app_running'), Arg(Collection, 'happy_new_tasks'), Arg(Sequence, 'old_non_draining_tasks'), DefaultArg(float, 'margin_factor'), ], BounceMethodResult] _bounce_method_funcs: Dict[str, BounceMethod] = {} def register_bounce_method( name: str) -> Callable[[BounceMethod], BounceMethod]: """Returns a decorator that registers that bounce function at a given name so get_bounce_method_func can find it.""" def outer(bounce_func: BounceMethod): _bounce_method_funcs[name] = bounce_func return bounce_func return outer
test_pattern = """ >>> m1= path_pat.match( "/anscombe/I" ) >>> m1.groupdict() {'dataset': 'I'} >>> m2= path_pat.match( "/anscombe/II/" ) >>> m2.groupdict() {'dataset': 'II'} >>> m3= path_pat.match( "/anscombe/" ) >>> m3.groupdict() {'dataset': ''} """ from typing import Callable, List, Tuple, Iterable from mypy_extensions import DefaultArg SR_Func = Callable[[str, List[Tuple[str, str]], DefaultArg(Tuple)], None] import traceback import urllib.parse def anscombe_app(environ: Dict, start_response: SR_Func) -> Iterable[bytes]: log = environ['wsgi.errors'] try: match = path_pat.match(environ['PATH_INFO']) set_id = match.group('dataset').upper() query = urllib.parse.parse_qs(environ['QUERY_STRING']) print(environ['PATH_INFO'], environ['QUERY_STRING'], match.groupdict(), file=log)
manager: ExchangeManager[Any, Any, Any] manager = ExchangeManager(self._peer, exchange_cls.response_cmd_type, peer.cancel_token) exchange = exchange_cls(manager) setattr(self, attr, exchange) def __iter__(self) -> Iterator[BaseExchange[Any, Any, Any]]: for key in self._exchange_config.keys(): yield getattr(self, key) def get_stats(self) -> Dict[str, str]: return { exchange.response_cmd_type.__name__: exchange.tracker.get_stats() for exchange in self } if TYPE_CHECKING: from mypy_extensions import DefaultArg BlockHeadersCallable = Callable[[ BaseExchangeHandler, BlockIdentifier, int, DefaultArg(int, 'skip'), DefaultArg(int, 'reverse') ], Awaitable[Tuple[BlockHeader, ...]]] # This class is only needed to please mypy for type checking class BaseChainExchangeHandler(BaseExchangeHandler): get_block_headers: 'BlockHeadersCallable'
ZK_LOCK_CONNECT_TIMEOUT_S = 10.0 # seconds to wait to connect to zookeeper ZK_LOCK_PATH = "/bounce" WAIT_CREATE_S = 3 WAIT_DELETE_S = 5 BounceMethodResult = TypedDict("BounceMethodResult", { "create_app": bool, "tasks_to_drain": Set }) BounceMethod = Callable[[ Arg(BounceMethodConfigDict, "new_config"), Arg(bool, "new_app_running"), Arg(Collection, "happy_new_tasks"), Arg(Sequence, "old_non_draining_tasks"), DefaultArg(float, "margin_factor"), ], BounceMethodResult, ] _bounce_method_funcs: Dict[str, BounceMethod] = {} def register_bounce_method( name: str) -> Callable[[BounceMethod], BounceMethod]: """Returns a decorator that registers that bounce function at a given name so get_bounce_method_func can find it.""" def outer(bounce_func: BounceMethod): _bounce_method_funcs[name] = bounce_func return bounce_func return outer
from typing import Callable, NamedTuple, Optional from mypy_extensions import Arg, DefaultArg class TxoKeyType(NamedTuple): tx_hash: bytes tx_index: int WaitingUpdateCallback = Callable[[Arg(bool, "advance"), DefaultArg(Optional[str], "message")], None]
from typing import ( Awaitable, Callable, Tuple, TYPE_CHECKING, ) from eth_typing import BlockIdentifier from eth.rlp.headers import BlockHeader from p2p.exchange import BaseExchangeHandler if TYPE_CHECKING: from mypy_extensions import DefaultArg BlockHeadersCallable = Callable[[ BaseExchangeHandler, BlockIdentifier, DefaultArg(int, 'max_headers'), DefaultArg(int, 'skip'), DefaultArg(int, 'reverse'), DefaultArg(float, 'timeout') ], Awaitable[Tuple[BlockHeader, ...]]] # This class is only needed to please mypy for type checking class BaseChainExchangeHandler(BaseExchangeHandler): get_block_headers: 'BlockHeadersCallable'
manager = ExchangeManager(self._peer, exchange_cls.response_cmd_type, peer.cancel_token) exchange = exchange_cls(manager) setattr(self, attr, exchange) def __iter__(self) -> Iterator[BaseExchange[Any, Any, Any]]: for key in self._exchange_config.keys(): yield getattr(self, key) def get_stats(self) -> Dict[str, str]: return { exchange.response_cmd_type.__name__: exchange.tracker.get_stats() for exchange in self } if TYPE_CHECKING: from mypy_extensions import DefaultArg BlockHeadersCallable = Callable[[ BaseExchangeHandler, BlockIdentifier, int, DefaultArg(int, 'skip'), DefaultArg(int, 'reverse'), DefaultArg(float, 'timeout') ], Awaitable[Tuple[BlockHeader, ...]]] # This class is only needed to please mypy for type checking class BaseChainExchangeHandler(BaseExchangeHandler): get_block_headers: 'BlockHeadersCallable'