##// END OF EJS Templates
Merge pull request #11271 from luzpaz/misc-typo-and-whitespaces...
Matthias Bussonnier -
r24495:0de2f49c merge
parent child Browse files
Show More
@@ -40,7 +40,7 b' import time'
40 # Constants
40 # Constants
41 #-----------------------------------------------------------------------------
41 #-----------------------------------------------------------------------------
42
42
43 # Roughtly equal to PyCF_MASK | PyCF_MASK_OBSOLETE as defined in pythonrun.h,
43 # Roughly equal to PyCF_MASK | PyCF_MASK_OBSOLETE as defined in pythonrun.h,
44 # this is used as a bitmask to extract future-related code flags.
44 # this is used as a bitmask to extract future-related code flags.
45 PyCF_MASK = functools.reduce(operator.or_,
45 PyCF_MASK = functools.reduce(operator.or_,
46 (getattr(__future__, fname).compiler_flag
46 (getattr(__future__, fname).compiler_flag
@@ -52,7 +52,7 b' PyCF_MASK = functools.reduce(operator.or_,'
52
52
53 def code_name(code, number=0):
53 def code_name(code, number=0):
54 """ Compute a (probably) unique name for code for caching.
54 """ Compute a (probably) unique name for code for caching.
55
55
56 This now expects code to be unicode.
56 This now expects code to be unicode.
57 """
57 """
58 hash_digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
58 hash_digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
@@ -71,7 +71,7 b' class CachingCompiler(codeop.Compile):'
71
71
72 def __init__(self):
72 def __init__(self):
73 codeop.Compile.__init__(self)
73 codeop.Compile.__init__(self)
74
74
75 # This is ugly, but it must be done this way to allow multiple
75 # This is ugly, but it must be done this way to allow multiple
76 # simultaneous ipython instances to coexist. Since Python itself
76 # simultaneous ipython instances to coexist. Since Python itself
77 # directly accesses the data structures in the linecache module, and
77 # directly accesses the data structures in the linecache module, and
@@ -95,7 +95,7 b' class CachingCompiler(codeop.Compile):'
95 def _fix_module_ds(self, module):
95 def _fix_module_ds(self, module):
96 """
96 """
97 Starting in python 3.7 the AST for mule have changed, and if
97 Starting in python 3.7 the AST for mule have changed, and if
98 the first expressions encountered is a string it is attached to the
98 the first expressions encountered is a string it is attached to the
99 `docstring` attribute of the `Module` ast node.
99 `docstring` attribute of the `Module` ast node.
100
100
101 This breaks IPython, as if this string is the only expression, IPython
101 This breaks IPython, as if this string is the only expression, IPython
@@ -108,14 +108,14 b' class CachingCompiler(codeop.Compile):'
108 new_body=[Expr(Str(docstring, lineno=1, col_offset=0), lineno=1, col_offset=0)]
108 new_body=[Expr(Str(docstring, lineno=1, col_offset=0), lineno=1, col_offset=0)]
109 new_body.extend(module.body)
109 new_body.extend(module.body)
110 return fix_missing_locations(Module(new_body))
110 return fix_missing_locations(Module(new_body))
111
111
112 def ast_parse(self, source, filename='<unknown>', symbol='exec'):
112 def ast_parse(self, source, filename='<unknown>', symbol='exec'):
113 """Parse code to an AST with the current compiler flags active.
113 """Parse code to an AST with the current compiler flags active.
114
114
115 Arguments are exactly the same as ast.parse (in the standard library),
115 Arguments are exactly the same as ast.parse (in the standard library),
116 and are passed to the built-in compile function."""
116 and are passed to the built-in compile function."""
117 return self._fix_module_ds(compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1))
117 return self._fix_module_ds(compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1))
118
118
119 def reset_compiler_flags(self):
119 def reset_compiler_flags(self):
120 """Reset compiler flags to default state."""
120 """Reset compiler flags to default state."""
121 # This value is copied from codeop.Compile.__init__, so if that ever
121 # This value is copied from codeop.Compile.__init__, so if that ever
@@ -127,10 +127,10 b' class CachingCompiler(codeop.Compile):'
127 """Flags currently active in the compilation process.
127 """Flags currently active in the compilation process.
128 """
128 """
129 return self.flags
129 return self.flags
130
130
131 def cache(self, code, number=0):
131 def cache(self, code, number=0):
132 """Make a name for a block of code, and cache the code.
132 """Make a name for a block of code, and cache the code.
133
133
134 Parameters
134 Parameters
135 ----------
135 ----------
136 code : str
136 code : str
@@ -138,7 +138,7 b' class CachingCompiler(codeop.Compile):'
138 number : int
138 number : int
139 A number which forms part of the code's name. Used for the execution
139 A number which forms part of the code's name. Used for the execution
140 counter.
140 counter.
141
141
142 Returns
142 Returns
143 -------
143 -------
144 The name of the cached code (as a string). Pass this as the filename
144 The name of the cached code (as a string). Pass this as the filename
@@ -174,7 +174,7 b' class CommandChainDispatcher:'
174 def shutdown_hook(self):
174 def shutdown_hook(self):
175 """ default shutdown hook
175 """ default shutdown hook
176
176
177 Typically, shotdown hooks should raise TryNext so all shutdown ops are done
177 Typically, shutdown hooks should raise TryNext so all shutdown ops are done
178 """
178 """
179
179
180 #print "default shutdown hook ok" # dbg
180 #print "default shutdown hook ok" # dbg
@@ -82,7 +82,7 b' class PrefilterManager(Configurable):'
82 prefilter consumes lines of input and produces transformed lines of
82 prefilter consumes lines of input and produces transformed lines of
83 input.
83 input.
84
84
85 The iplementation consists of two phases:
85 The implementation consists of two phases:
86
86
87 1. Transformers
87 1. Transformers
88 2. Checkers and handlers
88 2. Checkers and handlers
@@ -104,7 +104,7 b" _re_pattern_type = type(re.compile(''))"
104
104
105 def _safe_getattr(obj, attr, default=None):
105 def _safe_getattr(obj, attr, default=None):
106 """Safe version of getattr.
106 """Safe version of getattr.
107
107
108 Same as getattr, but will return ``default`` on any Exception,
108 Same as getattr, but will return ``default`` on any Exception,
109 rather than raising.
109 rather than raising.
110 """
110 """
@@ -246,7 +246,7 b' class PrettyPrinter(_PrettyPrinterBase):'
246 self.buffer.append(Breakable(sep, width, self))
246 self.buffer.append(Breakable(sep, width, self))
247 self.buffer_width += width
247 self.buffer_width += width
248 self._break_outer_groups()
248 self._break_outer_groups()
249
249
250 def break_(self):
250 def break_(self):
251 """
251 """
252 Explicitly insert a newline into the output, maintaining correct indentation.
252 Explicitly insert a newline into the output, maintaining correct indentation.
@@ -256,7 +256,7 b' class PrettyPrinter(_PrettyPrinterBase):'
256 self.output.write(' ' * self.indentation)
256 self.output.write(' ' * self.indentation)
257 self.output_width = self.indentation
257 self.output_width = self.indentation
258 self.buffer_width = 0
258 self.buffer_width = 0
259
259
260
260
261 def begin_group(self, indent=0, open=''):
261 def begin_group(self, indent=0, open=''):
262 """
262 """
@@ -282,7 +282,7 b' class PrettyPrinter(_PrettyPrinterBase):'
282 self.group_stack.append(group)
282 self.group_stack.append(group)
283 self.group_queue.enq(group)
283 self.group_queue.enq(group)
284 self.indentation += indent
284 self.indentation += indent
285
285
286 def _enumerate(self, seq):
286 def _enumerate(self, seq):
287 """like enumerate, but with an upper limit on the number of items"""
287 """like enumerate, but with an upper limit on the number of items"""
288 for idx, x in enumerate(seq):
288 for idx, x in enumerate(seq):
@@ -292,7 +292,7 b' class PrettyPrinter(_PrettyPrinterBase):'
292 self.text('...')
292 self.text('...')
293 return
293 return
294 yield idx, x
294 yield idx, x
295
295
296 def end_group(self, dedent=0, close=''):
296 def end_group(self, dedent=0, close=''):
297 """End a group. See `begin_group` for more details."""
297 """End a group. See `begin_group` for more details."""
298 self.indentation -= dedent
298 self.indentation -= dedent
@@ -765,7 +765,7 b' if _env_type is not dict:'
765
765
766 try:
766 try:
767 # In PyPy, types.DictProxyType is dict, setting the dictproxy printer
767 # In PyPy, types.DictProxyType is dict, setting the dictproxy printer
768 # using dict.setdefault avoids overwritting the dict printer
768 # using dict.setdefault avoids overwriting the dict printer
769 _type_pprinters.setdefault(types.DictProxyType,
769 _type_pprinters.setdefault(types.DictProxyType,
770 _dict_pprinter_factory('dict_proxy({', '})'))
770 _dict_pprinter_factory('dict_proxy({', '})'))
771 _type_pprinters[types.ClassType] = _type_pprint
771 _type_pprinters[types.ClassType] = _type_pprint
@@ -19,9 +19,9 b' def doctest_run():'
19 In [13]: run simplevars.py
19 In [13]: run simplevars.py
20 x is: 1
20 x is: 1
21 """
21 """
22
22
23 def doctest_runvars():
23 def doctest_runvars():
24 """Test that variables defined in scripts get loaded correcly via %run.
24 """Test that variables defined in scripts get loaded correclty via %run.
25
25
26 In [13]: run simplevars.py
26 In [13]: run simplevars.py
27 x is: 1
27 x is: 1
@@ -49,7 +49,7 b' def extract_vars(*names,**kw):'
49 """
49 """
50
50
51 depth = kw.get('depth',0)
51 depth = kw.get('depth',0)
52
52
53 callerNS = sys._getframe(depth+1).f_locals
53 callerNS = sys._getframe(depth+1).f_locals
54 return dict((k,callerNS[k]) for k in names)
54 return dict((k,callerNS[k]) for k in names)
55
55
@@ -58,7 +58,7 b' def extract_vars_above(*names):'
58 """Extract a set of variables by name from another frame.
58 """Extract a set of variables by name from another frame.
59
59
60 Similar to extractVars(), but with a specified depth of 1, so that names
60 Similar to extractVars(), but with a specified depth of 1, so that names
61 are exctracted exactly from above the caller.
61 are extracted exactly from above the caller.
62
62
63 This is simply a convenience function so that the very common case (for us)
63 This is simply a convenience function so that the very common case (for us)
64 of skipping exactly 1 frame doesn't have to construct a special dict for
64 of skipping exactly 1 frame doesn't have to construct a special dict for
@@ -93,4 +93,3 b' def extract_module_locals(depth=0):'
93 global_ns = f.f_globals
93 global_ns = f.f_globals
94 module = sys.modules[global_ns['__name__']]
94 module = sys.modules[global_ns['__name__']]
95 return (module, f.f_locals)
95 return (module, f.f_locals)
96
General Comments 0
You need to be logged in to leave comments. Login now