MCPcopy Create free account
hub / github.com/ipython/ipython / cache

Method cache

IPython/core/compilerop.py:115–136  ·  view source on GitHub ↗

Make a name for a block of code, and cache the code. Parameters ---------- code : str The Python source code to cache. number : int A number which forms part of the code's name. Used for the execution counter. Returns --

(self, code, number=0)

Source from the content-addressed store, hash-verified

113 return self.flags
114
115 def cache(self, code, number=0):
116 """Make a name for a block of code, and cache the code.
117
118 Parameters
119 ----------
120 code : str
121 The Python source code to cache.
122 number : int
123 A number which forms part of the code's name. Used for the execution
124 counter.
125
126 Returns
127 -------
128 The name of the cached code (as a string). Pass this as the filename
129 argument to compilation, so that tracebacks are correctly hooked up.
130 """
131 name = code_name(code, number)
132 entry = (len(code), time.time(),
133 [line+'\n' for line in code.splitlines()], name)
134 linecache.cache[name] = entry
135 linecache._ipython_cache[name] = entry
136 return name
137
138 @contextmanager
139 def extra_flags(self, flags):

Callers 4

test_cacheFunction · 0.95
test_cache_unicodeFunction · 0.95
run_cell_asyncMethod · 0.80

Calls 2

code_nameFunction · 0.85
timeMethod · 0.80

Tested by 3

test_cacheFunction · 0.76
test_cache_unicodeFunction · 0.76