python类Hashable()的实例源码

utils.py 文件源码 项目:pydev_docker 作者: Rastii 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def register_callable(self, key: Hashable):
        """
        Decorator, that is invoked withe an identifiable `key` parameter, that
        registers the callable that is decorated.

        Example:
            @registry.register_callable("DELETE")
            def delete_command(options):
                ...

        Args:
            key: The Hashable key to use that identifies the callable in the
                 in the registry.
        """
        def wrapper(f):
            self.register(key, f)

            @functools.wraps(f)
            def wrapped(*args, **kwargs):
                return f(*args, **kwargs)

            return wrapped
        return wrapper
utils.py 文件源码 项目:pydev_docker 作者: Rastii 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get(self, key: Hashable) -> Any:
        """
        Retrieves the value stored in the registry based on the `key` provided.

        Args:
            key: The key used to retrieve the stored object in the registry

        Returns:
            The object stored in the registry based on the `key` parameter

        Raises:
            RegistryKeyError: If the key was not found in the registry
        """
        if key not in self._registry:
            raise RegistryKeyError("Specified key: {} is not in the registry".format(key))

        return self._registry[key]
attachments.py 文件源码 项目:sqlalchemy-media 作者: pylover 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def key(self) -> Hashable:
        """
        Unique key for tracking this attachment. it will be generated during attachment process in
        :meth:`.attach` method.

        :type: Hashable
        """
        return self.get('key')
utils.py 文件源码 项目:deck-chores 作者: funkyfuture 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def lru_dict_arg_cache(func: Callable) -> Callable:
    # TODO? wrapper that allows maxsize
    def unpacking_func(func: Callable, arg: frozenset) -> Any:
        return func(dict(arg))

    _unpacking_func = _lru_cache_wrapper(partial(unpacking_func, func),  # type: ignore
                                         64, False, _CacheInfo)

    def packing_func(arg: Dict[Hashable, Hashable]) -> Any:
        return _unpacking_func(frozenset(arg.items()))

    update_wrapper(packing_func, func)
    packing_func.cache_info = _unpacking_func.cache_info  # type: ignore
    return packing_func
__init__.py 文件源码 项目:mccurse 作者: khardix 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self: 'lazydict', value_factory: Callable[[Hashable], Any]=None, *args, **kw):
        """Initialize new lazy dictionary.

        Keyword arguments:
            value_factory: The callable to use for constructing
                missing values.
            Other arguments are the same as for built-in `dict`.
        """

        self.value_factory = value_factory
        super().__init__(None, *args, **kw)
__init__.py 文件源码 项目:mccurse 作者: khardix 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __missing__(self: 'lazydict', key: Hashable) -> Any:
        """Attempts to construct the value and inserts it into the dictionary."""

        if self.value_factory is None:
            raise KeyError(key)

        value = self.value_factory(key)

        self[key] = value
        return value
utils.py 文件源码 项目:pydev_docker 作者: Rastii 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def register(self, key: Hashable, value: Any):
        """
        Registers any key / value combination.

        Args:
            key: The hashable key that identifies the object
            value: The value to store in the registry
        """
        self._registry[key] = value


问题


面经


文章

微信
公众号

扫码关注公众号