Python typing 模块,Hashable() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用typing.Hashable()

项目:pydev_docker    作者:Rastii    | 项目源码 | 文件源码
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
项目:pydev_docker    作者:Rastii    | 项目源码 | 文件源码
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]
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
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')
项目:deck-chores    作者:funkyfuture    | 项目源码 | 文件源码
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
项目:mccurse    作者:khardix    | 项目源码 | 文件源码
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)
项目:mccurse    作者:khardix    | 项目源码 | 文件源码
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
项目:pydev_docker    作者:Rastii    | 项目源码 | 文件源码
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