Show More
@@ -128,11 +128,11 b' else:' | |||||
128 | #----------------------------------------------------------------------------- |
|
128 | #----------------------------------------------------------------------------- | |
129 |
|
129 | |||
130 | def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType: |
|
130 | def removed_co_newlocals(function:types.FunctionType) -> types.FunctionType: | |
131 |
"""Return a function that do not create a new local scope. |
|
131 | """Return a function that do not create a new local scope. | |
132 |
|
132 | |||
133 | Given a function, create a clone of this function where the co_newlocal flag |
|
133 | Given a function, create a clone of this function where the co_newlocal flag | |
134 | has been removed, making this function code actually run in the sourounding |
|
134 | has been removed, making this function code actually run in the sourounding | |
135 |
scope. |
|
135 | scope. | |
136 |
|
136 | |||
137 | We need this in order to run asynchronous code in user level namespace. |
|
137 | We need this in order to run asynchronous code in user level namespace. | |
138 | """ |
|
138 | """ | |
@@ -175,7 +175,6 b' def _ast_asyncify(cell:str, wrapper_name:str) -> ast.Module:' | |||||
175 |
|
175 | |||
176 | Parameters |
|
176 | Parameters | |
177 | ---------- |
|
177 | ---------- | |
178 |
|
||||
179 | cell: str |
|
178 | cell: str | |
180 | The code cell to asyncronify |
|
179 | The code cell to asyncronify | |
181 | wrapper_name: str |
|
180 | wrapper_name: str | |
@@ -185,7 +184,6 b' def _ast_asyncify(cell:str, wrapper_name:str) -> ast.Module:' | |||||
185 |
|
184 | |||
186 | Returns |
|
185 | Returns | |
187 | ------- |
|
186 | ------- | |
188 |
|
||||
189 | ModuleType: |
|
187 | ModuleType: | |
190 | A module object AST containing **one** function named `wrapper_name`. |
|
188 | A module object AST containing **one** function named `wrapper_name`. | |
191 |
|
189 | |||
@@ -896,9 +894,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
896 | virtualenv was built, and it ignores the --no-site-packages option. A |
|
894 | virtualenv was built, and it ignores the --no-site-packages option. A | |
897 | warning will appear suggesting the user installs IPython in the |
|
895 | warning will appear suggesting the user installs IPython in the | |
898 | virtualenv, but for many cases, it probably works well enough. |
|
896 | virtualenv, but for many cases, it probably works well enough. | |
899 |
|
897 | |||
900 | Adapted from code snippets online. |
|
898 | Adapted from code snippets online. | |
901 |
|
899 | |||
902 | http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv |
|
900 | http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv | |
903 | """ |
|
901 | """ | |
904 | if 'VIRTUAL_ENV' not in os.environ: |
|
902 | if 'VIRTUAL_ENV' not in os.environ: | |
@@ -1067,7 +1065,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1067 |
|
1065 | |||
1068 | def register_post_execute(self, func): |
|
1066 | def register_post_execute(self, func): | |
1069 | """DEPRECATED: Use ip.events.register('post_run_cell', func) |
|
1067 | """DEPRECATED: Use ip.events.register('post_run_cell', func) | |
1070 |
|
1068 | |||
1071 | Register a function for calling after code execution. |
|
1069 | Register a function for calling after code execution. | |
1072 | """ |
|
1070 | """ | |
1073 | warn("ip.register_post_execute is deprecated, use " |
|
1071 | warn("ip.register_post_execute is deprecated, use " | |
@@ -1087,14 +1085,14 b' class InteractiveShell(SingletonConfigurable):' | |||||
1087 |
|
1085 | |||
1088 | def new_main_mod(self, filename, modname): |
|
1086 | def new_main_mod(self, filename, modname): | |
1089 | """Return a new 'main' module object for user code execution. |
|
1087 | """Return a new 'main' module object for user code execution. | |
1090 |
|
1088 | |||
1091 | ``filename`` should be the path of the script which will be run in the |
|
1089 | ``filename`` should be the path of the script which will be run in the | |
1092 | module. Requests with the same filename will get the same module, with |
|
1090 | module. Requests with the same filename will get the same module, with | |
1093 | its namespace cleared. |
|
1091 | its namespace cleared. | |
1094 |
|
1092 | |||
1095 | ``modname`` should be the module name - normally either '__main__' or |
|
1093 | ``modname`` should be the module name - normally either '__main__' or | |
1096 | the basename of the file without the extension. |
|
1094 | the basename of the file without the extension. | |
1097 |
|
1095 | |||
1098 | When scripts are executed via %run, we must keep a reference to their |
|
1096 | When scripts are executed via %run, we must keep a reference to their | |
1099 | __main__ module around so that Python doesn't |
|
1097 | __main__ module around so that Python doesn't | |
1100 | clear it, rendering references to module globals useless. |
|
1098 | clear it, rendering references to module globals useless. | |
@@ -1130,7 +1128,6 b' class InteractiveShell(SingletonConfigurable):' | |||||
1130 |
|
1128 | |||
1131 | Examples |
|
1129 | Examples | |
1132 | -------- |
|
1130 | -------- | |
1133 |
|
||||
1134 | In [15]: import IPython |
|
1131 | In [15]: import IPython | |
1135 |
|
1132 | |||
1136 | In [16]: m = _ip.new_main_mod(IPython.__file__, 'IPython') |
|
1133 | In [16]: m = _ip.new_main_mod(IPython.__file__, 'IPython') | |
@@ -1280,10 +1277,10 b' class InteractiveShell(SingletonConfigurable):' | |||||
1280 |
|
1277 | |||
1281 | def prepare_user_module(self, user_module=None, user_ns=None): |
|
1278 | def prepare_user_module(self, user_module=None, user_ns=None): | |
1282 | """Prepare the module and namespace in which user code will be run. |
|
1279 | """Prepare the module and namespace in which user code will be run. | |
1283 |
|
1280 | |||
1284 | When IPython is started normally, both parameters are None: a new module |
|
1281 | When IPython is started normally, both parameters are None: a new module | |
1285 | is created automatically, and its __dict__ used as the namespace. |
|
1282 | is created automatically, and its __dict__ used as the namespace. | |
1286 |
|
1283 | |||
1287 | If only user_module is provided, its __dict__ is used as the namespace. |
|
1284 | If only user_module is provided, its __dict__ is used as the namespace. | |
1288 | If only user_ns is provided, a dummy module is created, and user_ns |
|
1285 | If only user_ns is provided, a dummy module is created, and user_ns | |
1289 | becomes the global namespace. If both are provided (as they may be |
|
1286 | becomes the global namespace. If both are provided (as they may be | |
@@ -1404,7 +1401,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1404 | def all_ns_refs(self): |
|
1401 | def all_ns_refs(self): | |
1405 | """Get a list of references to all the namespace dictionaries in which |
|
1402 | """Get a list of references to all the namespace dictionaries in which | |
1406 | IPython might store a user-created object. |
|
1403 | IPython might store a user-created object. | |
1407 |
|
1404 | |||
1408 | Note that this does not include the displayhook, which also caches |
|
1405 | Note that this does not include the displayhook, which also caches | |
1409 | objects from the output.""" |
|
1406 | objects from the output.""" | |
1410 | return [self.user_ns, self.user_global_ns, self.user_ns_hidden] + \ |
|
1407 | return [self.user_ns, self.user_global_ns, self.user_ns_hidden] + \ | |
@@ -1582,15 +1579,15 b' class InteractiveShell(SingletonConfigurable):' | |||||
1582 | def drop_by_id(self, variables): |
|
1579 | def drop_by_id(self, variables): | |
1583 | """Remove a dict of variables from the user namespace, if they are the |
|
1580 | """Remove a dict of variables from the user namespace, if they are the | |
1584 | same as the values in the dictionary. |
|
1581 | same as the values in the dictionary. | |
1585 |
|
1582 | |||
1586 | This is intended for use by extensions: variables that they've added can |
|
1583 | This is intended for use by extensions: variables that they've added can | |
1587 | be taken back out if they are unloaded, without removing any that the |
|
1584 | be taken back out if they are unloaded, without removing any that the | |
1588 | user has overwritten. |
|
1585 | user has overwritten. | |
1589 |
|
1586 | |||
1590 | Parameters |
|
1587 | Parameters | |
1591 | ---------- |
|
1588 | ---------- | |
1592 | variables : dict |
|
1589 | variables : dict | |
1593 | A dictionary mapping object names (as strings) to the objects. |
|
1590 | A dictionary mapping object names (as strings) to the objects. | |
1594 | """ |
|
1591 | """ | |
1595 | for name, obj in variables.items(): |
|
1592 | for name, obj in variables.items(): | |
1596 | if name in self.user_ns and self.user_ns[name] is obj: |
|
1593 | if name in self.user_ns and self.user_ns[name] is obj: | |
@@ -1884,10 +1881,10 b' class InteractiveShell(SingletonConfigurable):' | |||||
1884 |
|
1881 | |||
1885 | def validate_stb(stb): |
|
1882 | def validate_stb(stb): | |
1886 | """validate structured traceback return type |
|
1883 | """validate structured traceback return type | |
1887 |
|
1884 | |||
1888 | return type of CustomTB *should* be a list of strings, but allow |
|
1885 | return type of CustomTB *should* be a list of strings, but allow | |
1889 | single strings or None, which are harmless. |
|
1886 | single strings or None, which are harmless. | |
1890 |
|
1887 | |||
1891 | This function will *always* return a list of strings, |
|
1888 | This function will *always* return a list of strings, | |
1892 | and will raise a TypeError if stb is inappropriate. |
|
1889 | and will raise a TypeError if stb is inappropriate. | |
1893 | """ |
|
1890 | """ | |
@@ -2289,14 +2286,12 b' class InteractiveShell(SingletonConfigurable):' | |||||
2289 | Parameters |
|
2286 | Parameters | |
2290 | ---------- |
|
2287 | ---------- | |
2291 | magic_name : str |
|
2288 | magic_name : str | |
2292 | Name of the desired magic function, without '%' prefix. |
|
2289 | Name of the desired magic function, without '%' prefix. | |
2293 |
|
||||
2294 | line : str |
|
2290 | line : str | |
2295 | The rest of the input line as a single string. |
|
2291 | The rest of the input line as a single string. | |
2296 |
|
||||
2297 | _stack_depth : int |
|
2292 | _stack_depth : int | |
2298 | If run_line_magic() is called from magic() then _stack_depth=2. |
|
2293 | If run_line_magic() is called from magic() then _stack_depth=2. | |
2299 | This is added to ensure backward compatibility for use of 'get_ipython().magic()' |
|
2294 | This is added to ensure backward compatibility for use of 'get_ipython().magic()' | |
2300 | """ |
|
2295 | """ | |
2301 | fn = self.find_line_magic(magic_name) |
|
2296 | fn = self.find_line_magic(magic_name) | |
2302 | if fn is None: |
|
2297 | if fn is None: | |
@@ -2333,7 +2328,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2333 | Parameters |
|
2328 | Parameters | |
2334 | ---------- |
|
2329 | ---------- | |
2335 | stack_depth : int |
|
2330 | stack_depth : int | |
2336 | Depth relative to calling frame |
|
2331 | Depth relative to calling frame | |
2337 | """ |
|
2332 | """ | |
2338 | return sys._getframe(stack_depth + 1).f_locals |
|
2333 | return sys._getframe(stack_depth + 1).f_locals | |
2339 |
|
2334 | |||
@@ -2343,13 +2338,11 b' class InteractiveShell(SingletonConfigurable):' | |||||
2343 | Parameters |
|
2338 | Parameters | |
2344 | ---------- |
|
2339 | ---------- | |
2345 | magic_name : str |
|
2340 | magic_name : str | |
2346 | Name of the desired magic function, without '%' prefix. |
|
2341 | Name of the desired magic function, without '%' prefix. | |
2347 |
|
||||
2348 | line : str |
|
2342 | line : str | |
2349 | The rest of the first input line as a single string. |
|
2343 | The rest of the first input line as a single string. | |
2350 |
|
||||
2351 | cell : str |
|
2344 | cell : str | |
2352 | The body of the cell as a (possibly multiline) string. |
|
2345 | The body of the cell as a (possibly multiline) string. | |
2353 | """ |
|
2346 | """ | |
2354 | fn = self.find_cell_magic(magic_name) |
|
2347 | fn = self.find_cell_magic(magic_name) | |
2355 | if fn is None: |
|
2348 | if fn is None: |
General Comments 0
You need to be logged in to leave comments.
Login now