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


Python typecheck.optional函数代码示例

本文整理汇总了Python中typecheck.optional函数的典型用法代码示例。如果您正苦于以下问题:Python optional函数的具体用法?Python optional怎么用?Python optional使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: render

 def render(self, layout: str="", labels: tc.optional(bool)=None,
            mode: str="", source: str="", size: int=0,
            font_size: tc.optional(int)=None):
     if layout:
         self.layout = layout
     if labels is not None:
         self.labels = labels
     if mode:
         self.mode = mode
     if source:
         self.source = source
         self.weights = Counter()
     if size:
         self.size = size
     if font_size is not None:
         self.font_size = font_size
     if self.mode == "simple":
         self.node_multiplier = 0.7
     elif self.mode == "full":
         self.node_multiplier = 20
     elif self.mode == "reduced-structure":
         self.node_multiplier = 4
     elif self.mode == "simple-structure":
         self.node_multiplier = 4
         self.font_size = 10
     elif self.mode == "full-structure":
         self.node_multiplier = 6
         self.font_size = 8
     if not self.weights:
         self.finder.run_script(self.source)
     self.draw()
开发者ID:masteringmatplotlib,项目名称:architecture,代码行数:31,代码来源:modgraph.py

示例2: __init__

    def __init__(self, *,
                 timeout: optional(float) = None,
                 interface: optional(str) = None,
                 protocol: optional(str) = None,
                 parameters: optional(dict) = None,
                 description: optional(str) = None):

        # infinite "requests" can only be anonymous, "normal" requests
        # having a deadline must be assigned an interface and protocol

        self._start = time()
        if timeout is not None:
            self._deadline = self._start + timeout
            assert interface is not None and protocol is not None, \
                   "request with deadline from unspecified interface/protocol"
        else:
            self._deadline = None
            assert interface is None and protocol is None, \
                   "infinite request from specific interface/protocol"

        self._interface, self._protocol = interface, protocol
        self._parameters = parameters or {}

        request_time = strftime("%Y%m%d%H%M%S")
        random_id = b2a_hex(urandom(6)).decode("ascii").upper()
        self._unique_id = "RQ-{0:s}-{1:s}".format(request_time, random_id)
        self._description = description
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:27,代码来源:request.py

示例3: import_hook

 def import_hook(self, name: str, caller: tc.optional(Module)=None,
                 fromlist: tc.optional(list)=None,
                 level: int=-1) -> tc.optional(Module):
     if self.matches(name):
         if caller:
             if self.debug:
                 print(caller.__name__, " -> ", name)
             self.cf_weights[name] += 1
             self.cf_imports[(caller.__name__, name)] = 1
         super().import_hook(name, caller, fromlist, level)
开发者ID:masteringmatplotlib,项目名称:architecture,代码行数:10,代码来源:modfind.py

示例4: fake_request

def fake_request(timeout: optional(float) = None,
                 interface: optional(str) = "__fake__") -> Request:

    if timeout is not None:
        request = Request(timeout = timeout, interface = interface, protocol = "n/a",
                          parameters = dict(auth_tokens = {}))
    else:
        request = InfiniteRequest()

    current_thread()._request = request
    return request
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:11,代码来源:request.py

示例5: get_private_thread_pool

def get_private_thread_pool(pool_name: optional(str) = None,
                            pool_size: optional(int) = None,
                            *, __source_module_name) -> ThreadPool:

    pool_name = "{0:s}{1:s}".format(__source_module_name,
                                    pool_name is not None and "/{0:s}".format(pool_name) or "")
    with _pools_lock:

        if pool_name not in _private_pools:
            pool_size = pool_size or pmnc.config_interfaces.get("thread_count")
            _private_pools[pool_name] = ThreadPool(pool_name, pool_size)

        return _private_pools[pool_name]
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:13,代码来源:shared_pools.py

示例6: begin_work

 def begin_work(self, timeout: optional(float) = None) -> (bool, optional(int)):
     timeout = Timeout(timeout or self._idle_timeout + 1.0)
     while not timeout.expired:
         if current_thread().stopped():
             return True, None
         self._signal.wait(min(timeout.remain, 3.0)) # this may spend waiting slightly less, but it's ok
         with self._lock:
             for i, source in enumerate(self._sources):
                 if source.begin_work():
                     return False, i
             else:
                 self._signal.clear()
     else:
         return False, None
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:14,代码来源:work_sources.py

示例7: _collapsed_bar

def _collapsed_bar(s: optional((int, int))) -> str:

    if s is None:
        return " "

    low, high = s; assert 0 <= low <= high <= 39
    return box_chars[high // 5]
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:7,代码来源:interface_performance.py

示例8: locate

 def locate(self, module_name: by_regex("^[A-Za-z0-9_-]{1,128}\\.pyc?$")) -> optional(os_path.isfile):
     if module_name in self._listdir(self._cage_directory):
         return os_path.join(self._cage_directory, module_name)
     elif self._shared_directory and module_name in self._listdir(self._shared_directory):
         return os_path.join(self._shared_directory, module_name)
     else:
         return None # not found
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:7,代码来源:module_locator.py

示例9: execute_async

def execute_async(target_cage: valid_cage_name, module: valid_module_name,
                  method: valid_method_name, args: tuple, kwargs: dict, *,
                  queue: optional(valid_queue_name) = None, id: optional(str) = None,
                  expires_in: optional(float) = None) -> valid_retry_id:

    # if the caller used deprecated syntax pmnc("target_cage:retry"),
    # the name of the queue is set to None meaning "default queue"

    if queue is None: # in which case the configured default value is used
        queue = pmnc.config.get("retry_queue")

    # execution of asynchronous calls is done through
    # a special resource "pmnc" of protocol "retry"

    xa = pmnc.transaction.create()
    xa.pmnc(target_cage, queue = queue, id = id, expires_in = expires_in).\
       __getattr__(module).__getattr__(method)(*args, **kwargs)
    return xa.execute()[0]
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:18,代码来源:remote_call.py

示例10: __init__

    def __init__(self, source_module_name, *,
                 accept: optional(callable) = None,
                 sync_commit: optional(bool) = True,
                 **options):

        self._source_module_name = source_module_name
        self._accept = accept or self._default_accept
        self._sync_commit = sync_commit
        self._options = options

        transaction_time = strftime("%Y%m%d%H%M%S")
        random_id = b2a_hex(urandom(6)).decode("ascii").upper()
        self._xid = "XA-{0:s}-{1:s}".format(transaction_time, random_id)
        self._details = None

        self._resources, self._results = [], InterlockedQueue()
        self._decision, self._commit = Event(), Event()
        self._transaction_rate_sampler.tick()
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:18,代码来源:transaction.py

示例11: get_queue

def get_queue(
    name: str,
    *,
    __source_module_name,
    re_len: int,
    pagesize: optional(int) = 32768,
    q_extentsize: optional(int) = 128,
    re_pad: optional(int) = 0x00,
    **db_opts
):

    db_opts["re_len"] = re_len
    db_opts["pagesize"] = pagesize
    db_opts["q_extentsize"] = q_extentsize
    db_opts["re_pad"] = re_pad

    module_state = _get_module_state(__source_module_name)
    return module_state.get_queue_db(name, **db_opts)
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:18,代码来源:state.py

示例12: wait

 def wait(self, event: optional(Event) = None) -> bool: # respects wall-time timeout, see issue9892
     remain, event = self.remain, event or self._never_set
     while remain > 0.0:
         event.wait(remain)
         if event.is_set():
             return True
         else:
             remain = self.remain
     else:
         return False
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:10,代码来源:timeout.py

示例13: end_request

def end_request(success: optional(bool), request: optional(Request) = None):

    outcome = success and "success" or "failure"
    request = request or pmnc.request

    response_ms = int(request.elapsed * 1000)
    pmnc.performance.sample("interface.{0:s}.response_time.{1:s}".\
                            format(request.interface, outcome), response_ms)
    pmnc.performance.event("interface.{0:s}.response_rate.{1:s}".\
                           format(request.interface, outcome))

    request_count = _request_factory.destroyed() # we don't care exactly which request is being destroyed

    active_requests = request_count > 0 and ", {0:d} request(s) are still active".format(request_count) or ""
    request_description = "{0:s} ".format(request.description) if request is not current_thread()._request else ""
    request_outcome = "ends with {0:s}".format(outcome) if success is not None else "is being abandoned"

    pmnc.log.debug("request {0:s}{1:s}{2:s}".\
                   format(request_description, request_outcome, active_requests))
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:19,代码来源:interfaces.py

示例14: extract

def extract() -> optional((int, dict, dict)):

    result = {}

    with _perf_lock:

        # establish a reference base time between 60s shared stats from 10s shared stats

        if _perf_dump_60s:
            base_time = _perf_dump_60s[-1][0] + 60
        else:
            for x in _perf_dump_10s:
                if x is not None:
                    base_time = x[0] // 60 * 60
                    break
            else:
                return None # no stats at all

        # copy the 60s shared stats

        for t, d in reversed(_perf_dump_60s):
            time_delta = base_time - t
            assert time_delta % 60 == 0
            minutes_back = time_delta // 60
            if 0 < minutes_back <= 59:
                i = 59 - minutes_back
                for k, v in d.items():
                    result.setdefault(k, ([None] * 59, [None] * 6))[0][i] = v

        # copy the 10s shared stats

        for x in _perf_dump_10s:
            if x is not None:
                t, d = x
                time_delta = t - base_time
                assert time_delta % 10 == 0
                slices_forward = time_delta // 10
                if 0 <= slices_forward < 6:
                    i = slices_forward
                    for k, v in d.items():
                        result.setdefault(k, ([None] * 59, [None] * 6))[1][i] = v

        # copy the global statistics

        stats = _perf_stats.copy()

    return base_time, result, stats
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:47,代码来源:performance.py

示例15: __init__

    def __init__(self, name: str, *,
                 source_cages: tuple_of(valid_cage_name),
                 request_timeout: optional(float) = None,
                 **kwargs):

        self._name = name
        self._source_cages = source_cages

        self._request_timeout = request_timeout or \
                                pmnc.config_interfaces.get("request_timeout") # this is now static

        if pmnc.request.self_test != __name__:
            self._poll = lambda cage: pmnc(cage).reverse_call.poll()
            self._post = lambda cage, request_id, response: pmnc(cage).reverse_call.post(request_id, response)
        else: # self-test
            self._process_revrpc_request = kwargs["process_revrpc_request"]
            self._poll = kwargs["poll"]
            self._post = kwargs["post"]
开发者ID:Tombar,项目名称:pythomnic3k,代码行数:18,代码来源:protocol_revrpc.py


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