##// END OF EJS Templates
please linter
Matthias Bussonnier -
Show More
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -217,11 +217,13 b' def _tr_system(line_info:LineInfo):'
217 cmd = line_info.line.lstrip().lstrip(ESC_SHELL)
217 cmd = line_info.line.lstrip().lstrip(ESC_SHELL)
218 return '%sget_ipython().system(%r)' % (line_info.pre, cmd)
218 return '%sget_ipython().system(%r)' % (line_info.pre, cmd)
219
219
220
220 def _tr_system2(line_info:LineInfo):
221 def _tr_system2(line_info: LineInfo):
221 "Translate lines escaped with: !!"
222 "Translate lines escaped with: !!"
222 cmd = line_info.line.lstrip()[2:]
223 cmd = line_info.line.lstrip()[2:]
223 return '%sget_ipython().getoutput(%r)' % (line_info.pre, cmd)
224 return '%sget_ipython().getoutput(%r)' % (line_info.pre, cmd)
224
225
226
225 def _tr_help(line_info:LineInfo):
227 def _tr_help(line_info: LineInfo):
226 "Translate lines escaped with: ?/??"
228 "Translate lines escaped with: ?/??"
227 # A naked help line should just fire the intro help screen
229 # A naked help line should just fire the intro help screen
@@ -230,6 +232,7 b' def _tr_help(line_info:LineInfo):'
230
232
231 return _make_help_call(line_info.ifun, line_info.esc, line_info.pre)
233 return _make_help_call(line_info.ifun, line_info.esc, line_info.pre)
232
234
235
233 def _tr_magic(line_info:LineInfo):
236 def _tr_magic(line_info: LineInfo):
234 "Translate lines escaped with: %"
237 "Translate lines escaped with: %"
235 tpl = '%sget_ipython().run_line_magic(%r, %r)'
238 tpl = '%sget_ipython().run_line_magic(%r, %r)'
@@ -241,16 +244,19 b' def _tr_magic(line_info:LineInfo):'
241 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
244 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
242 return tpl % (line_info.pre, t_magic_name, t_magic_arg_s)
245 return tpl % (line_info.pre, t_magic_name, t_magic_arg_s)
243
246
247
244 def _tr_quote(line_info:LineInfo):
248 def _tr_quote(line_info: LineInfo):
245 "Translate lines escaped with: ,"
249 "Translate lines escaped with: ,"
246 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
250 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
247 '", "'.join(line_info.the_rest.split()) )
251 '", "'.join(line_info.the_rest.split()) )
248
252
253
249 def _tr_quote2(line_info:LineInfo):
254 def _tr_quote2(line_info: LineInfo):
250 "Translate lines escaped with: ;"
255 "Translate lines escaped with: ;"
251 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
256 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
252 line_info.the_rest)
257 line_info.the_rest)
253
258
259
254 def _tr_paren(line_info:LineInfo):
260 def _tr_paren(line_info: LineInfo):
255 "Translate lines escaped with: /"
261 "Translate lines escaped with: /"
256 return '%s%s(%s)' % (line_info.pre, line_info.ifun,
262 return '%s%s(%s)' % (line_info.pre, line_info.ifun,
@@ -267,8 +273,7 b' tr = { ESC_SHELL : _tr_system,'
267
273
268 @StatelessInputTransformer.wrap
274 @StatelessInputTransformer.wrap
269 def escaped_commands(line:str):
275 def escaped_commands(line: str):
270 """Transform escaped commands - %magic, !system, ?help + various autocalls.
276 """Transform escaped commands - %magic, !system, ?help + various autocalls."""
271 """
272 if not line or line.isspace():
277 if not line or line.isspace():
273 return line
278 return line
274 lineinf = LineInfo(line)
279 lineinf = LineInfo(line)
@@ -57,6 +57,7 b' def execfile(fname, glob, loc=None, compiler=None):'
57
57
58 PYPY = platform.python_implementation() == "PyPy"
58 PYPY = platform.python_implementation() == "PyPy"
59
59
60
60 # Cython still rely on that as a Dec 28 2019
61 # Cython still rely on that as a Dec 28 2019
61 # See https://github.com/cython/cython/pull/3291 and
62 # See https://github.com/cython/cython/pull/3291 and
62 # https://github.com/ipython/ipython/issues/12068
63 # https://github.com/ipython/ipython/issues/12068
@@ -652,7 +652,9 b' def _get_or_default(mylist, i, default=None):'
652 return mylist[i]
652 return mylist[i]
653
653
654
654
655 def compute_item_matrix(items, row_first:bool=False, empty=None,*, separator_size=2, displaywidth=80) -> Tuple[List[List[int]], Dict[str, int]] :
655 def compute_item_matrix(
656 items, row_first: bool = False, empty=None, *, separator_size=2, displaywidth=80
657 ) -> Tuple[List[List[int]], Dict[str, int]]:
656 """Returns a nested list, and info to columnize items
658 """Returns a nested list, and info to columnize items
657
659
658 Parameters
660 Parameters
@@ -707,8 +709,13 b' def compute_item_matrix(items, row_first:bool=False, empty=None,*, separator_si'
707 stacklevel=2,
709 stacklevel=2,
708 category=PendingDeprecationWarning,
710 category=PendingDeprecationWarning,
709 )
711 )
710 info = _find_optimal(list(map(len, items)), row_first, separator_size=separator_size, displaywidth=displaywidth)
712 info = _find_optimal(
711 nrow, ncol = info['max_rows'], info['num_columns']
713 list(map(len, items)),
714 row_first,
715 separator_size=separator_size,
716 displaywidth=displaywidth,
717 )
718 nrow, ncol = info["max_rows"], info["num_columns"]
712 if row_first:
719 if row_first:
713 return ([[_get_or_default(items, r * ncol + c, default=empty) for c in range(ncol)] for r in range(nrow)], info)
720 return ([[_get_or_default(items, r * ncol + c, default=empty) for c in range(ncol)] for r in range(nrow)], info)
714 else:
721 else:
@@ -742,14 +749,21 b' def columnize(items, row_first=False, separator=" ", displaywidth=80, spread=Fa'
742 category=PendingDeprecationWarning,
749 category=PendingDeprecationWarning,
743 )
750 )
744 if not items:
751 if not items:
745 return '\n'
752 return "\n"
746 matrix:List[List[int]]
753 matrix: List[List[int]]
747 matrix, info = compute_item_matrix(items, row_first=row_first, separator_size=len(separator), displaywidth=displaywidth)
754 matrix, info = compute_item_matrix(
755 items,
756 row_first=row_first,
757 separator_size=len(separator),
758 displaywidth=displaywidth,
759 )
748 if spread:
760 if spread:
749 separator = separator.ljust(int(info['optimal_separator_width']))
761 separator = separator.ljust(int(info["optimal_separator_width"]))
750 fmatrix:List[filter[int]] = [filter(None, x) for x in matrix]
762 fmatrix: List[filter[int]] = [filter(None, x) for x in matrix]
751 sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['column_widths'])])
763 sjoin = lambda x: separator.join(
752 return '\n'.join(map(sjoin, fmatrix))+'\n'
764 [y.ljust(w, " ") for y, w in zip(x, info["column_widths"])]
765 )
766 return "\n".join(map(sjoin, fmatrix)) + "\n"
753
767
754
768
755 def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""):
769 def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""):
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -24,7 +24,9 b' def generate_tokens(readline):'
24 return
24 return
25
25
26
26
27 def generate_tokens_catch_errors(readline, extra_errors_to_catch:Optional[List[str]]=None):
27 def generate_tokens_catch_errors(
28 readline, extra_errors_to_catch: Optional[List[str]] = None
29 ):
28 default_errors_to_catch = [
30 default_errors_to_catch = [
29 "unterminated string literal",
31 "unterminated string literal",
30 "invalid non-printable character",
32 "invalid non-printable character",
@@ -86,6 +88,7 b' def line_at_cursor(cell, cursor_pos=0):'
86 line = ""
88 line = ""
87 return (line, offset)
89 return (line, offset)
88
90
91
89 def token_at_cursor(cell:str, cursor_pos:int=0):
92 def token_at_cursor(cell: str, cursor_pos: int = 0):
90 """Get the token at a given cursor
93 """Get the token at a given cursor
91
94
General Comments 0
You need to be logged in to leave comments. Login now