63
63
64
64
65
65
class async_cache :
66
+ """
67
+ A wrapper for caching coroutines.
68
+
69
+ Parameters
70
+ ----------
71
+ cache_dict : dict
72
+ the dictionary to use for caching.
73
+ Provide this to use the same cache for multiple wrappers.
74
+
75
+ Examples
76
+ --------
77
+ >>> @async_cache()
78
+ ... async def calc():
79
+ ... return 8
80
+
81
+ """
82
+
66
83
def __init__ (self , cache_dict = None ):
84
+ """Init."""
67
85
self ._dict = cache_dict or {}
68
86
69
87
def __call__ (
70
88
self , func : Callable [..., Coroutine [None , None , T ]]
71
89
) -> Callable [..., Coroutine [None , None , T ]]:
90
+ """Wrap a function and return it."""
91
+
72
92
@wraps (func )
73
93
async def get (* args , ** kwargs ):
74
94
key = (args , tuple (map (tuple , kwargs .items ())))
@@ -84,12 +104,11 @@ async def get(*args, **kwargs):
84
104
85
105
# -- Git ---------------------------------------------------------------------
86
106
87
- # The git commands in this section is partially sourced and modified from
107
+ # Fragments of the following git logic are sourced from
88
108
# https://github.com/pre-commit/pre-commit/blob/main/pre_commit/git.py
89
- # https://github.com/pre-commit/pre-commit/blob/main/pre_commit/util.py
90
109
#
91
110
# Original Copyright (c) 2014 pre-commit dev team: Anthony Sottile, Ken Struys
92
-
111
+ # MIT License
93
112
94
113
# prevents errors on windows
95
114
NO_FS_MONITOR = ("-c" , "core.useBuiltinFSMonitor=false" )
0 commit comments