diff --git a/news/use-black-20.8.rst b/news/use-black-20.8.rst new file mode 100644 index 0000000000..bbadb7cfd5 --- /dev/null +++ b/news/use-black-20.8.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* upgrade black formatter to version 20.8b1 + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/requirements/tests.txt b/requirements/tests.txt index 2d21066589..c52a117c6a 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -8,6 +8,6 @@ prompt-toolkit>=3.0 pygments>=2.2 codecov coverage -black==19.10b0 --pre +black==20.8b1 --pre pre-commit mypy==0.790 diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py index 2485b0731d..2fa5a26a4b 100644 --- a/xonsh/commands_cache.py +++ b/xonsh/commands_cache.py @@ -59,8 +59,8 @@ def is_empty(self): @staticmethod def get_possible_names(name): """Generates the possible `PATHEXT` extension variants of a given executable - name on Windows as a list, conserving the ordering in `PATHEXT`. - Returns a list as `name` being the only item in it on other platforms.""" + name on Windows as a list, conserving the ordering in `PATHEXT`. + Returns a list as `name` being the only item in it on other platforms.""" if ON_WINDOWS: pathext = builtins.__xonsh__.env.get("PATHEXT", []) name = name.upper() diff --git a/xonsh/completers/bash_completion.py b/xonsh/completers/bash_completion.py index 24ce483fa5..4a2cc7ee87 100644 --- a/xonsh/completers/bash_completion.py +++ b/xonsh/completers/bash_completion.py @@ -115,7 +115,7 @@ def _get_bash_completions_source(paths=None): def _bash_get_sep(): - """ Returns the appropriate filepath separator char depending on OS and + """Returns the appropriate filepath separator char depending on OS and xonsh options set """ if platform.system() == "Windows": diff --git a/xonsh/jobs.py b/xonsh/jobs.py index aeb7f503bc..e86510d94f 100644 --- a/xonsh/jobs.py +++ b/xonsh/jobs.py @@ -287,8 +287,7 @@ def print_one_job(num, outfile=sys.stdout): def get_next_job_number(): - """Get the lowest available unique job number (for the next job created). - """ + """Get the lowest available unique job number (for the next job created).""" _clear_dead_jobs() i = 1 while i in builtins.__xonsh__.all_jobs: diff --git a/xonsh/lib/collections.py b/xonsh/lib/collections.py index 349766f30d..48332592e6 100644 --- a/xonsh/lib/collections.py +++ b/xonsh/lib/collections.py @@ -22,7 +22,7 @@ def __new__(cls): class ChainDB(ChainMap): - """ A ChainMap who's ``_getitem__`` returns either a ChainDB or + """A ChainMap who's ``_getitem__`` returns either a ChainDB or the result. The results resolve to the outermost mapping.""" def __getitem__(self, key): diff --git a/xonsh/lib/itertools.py b/xonsh/lib/itertools.py index d75ce00ff4..1b64fc201f 100644 --- a/xonsh/lib/itertools.py +++ b/xonsh/lib/itertools.py @@ -1,30 +1,30 @@ def as_iterable(iterable_or_scalar): """Utility for converting an object to an iterable. - Parameters - ---------- - iterable_or_scalar : anything + Parameters + ---------- + iterable_or_scalar : anything - Returns - ------- - l : iterable - If `obj` was None, return the empty tuple. - If `obj` was not iterable returns a 1-tuple containing `obj`. - Otherwise return `obj` + Returns + ------- + l : iterable + If `obj` was None, return the empty tuple. + If `obj` was not iterable returns a 1-tuple containing `obj`. + Otherwise return `obj` - Notes - ----- - Although string types are iterable in Python, we are treating them as not iterable in this - method. Thus, as_iterable(string) returns (string, ) + Notes + ----- + Although string types are iterable in Python, we are treating them as not iterable in this + method. Thus, as_iterable(string) returns (string, ) - Examples - --------- - >>> as_iterable(1) - (1,) - >>> as_iterable([1, 2, 3]) - [1, 2, 3] - >>> as_iterable("my string") - ("my string", ) - """ + Examples + --------- + >>> as_iterable(1) + (1,) + >>> as_iterable([1, 2, 3]) + [1, 2, 3] + >>> as_iterable("my string") + ("my string", ) + """ if iterable_or_scalar is None: return () diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py index fb2374c3ae..1fc9290159 100644 --- a/xonsh/parsers/base.py +++ b/xonsh/parsers/base.py @@ -658,16 +658,16 @@ def _parse_error(self, msg, loc): # def p_start_symbols(self, p): - """start_symbols : single_input - | file_input - | eval_input - | empty + """ + start_symbols : single_input + | file_input + | eval_input + | empty """ p[0] = p[1] def p_single_input(self, p): - """single_input : compound_stmt NEWLINE - """ + """single_input : compound_stmt NEWLINE""" p1 = empty_list_if_newline(p[1]) p0 = ast.Interactive(body=p1) p[0] = p0 @@ -691,20 +691,21 @@ def p_file_stmts_files(self, p): p[0] = p[1] + p2 def p_newline_or_stmt(self, p): - """newline_or_stmt : NEWLINE - | stmt + """ + newline_or_stmt : NEWLINE + | stmt """ p[0] = p[1] def p_newlines(self, p): - """newlines : NEWLINE - | newlines NEWLINE + """ + newlines : NEWLINE + | newlines NEWLINE """ p[0] = p[1] if len(p) == 2 else p[1] + p[2] def p_eval_input(self, p): - """eval_input : testlist newlines_opt - """ + """eval_input : testlist newlines_opt""" p1 = p[1] p[0] = ast.Expression(body=p1, lineno=p1.lineno, col_offset=p1.col_offset) @@ -773,8 +774,9 @@ def p_decorator_call(self, p): p[0] = p0 def p_decorators(self, p): - """decorators : decorator - | decorators decorator + """ + decorators : decorator + | decorators decorator """ p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]] @@ -1096,14 +1098,16 @@ def p_comma_pow_vfpdef(self, p): p[0] = p[3] def p_stmt(self, p): - """stmt : simple_stmt - | compound_stmt + """ + stmt : simple_stmt + | compound_stmt """ p[0] = p[1] def p_stmt_list(self, p): - """stmt_list : stmt - | stmt_list stmt + """ + stmt_list : stmt + | stmt_list stmt """ if len(p) == 2: p[0] = p[1] @@ -1111,8 +1115,9 @@ def p_stmt_list(self, p): p[0] = p[1] + p[2] def p_semi_opt(self, p): - """semi_opt : SEMI - | empty + """ + semi_opt : SEMI + | empty """ if len(p) == 2: p[0] = p[1] @@ -1130,14 +1135,15 @@ def p_simple_stmt_many(self, p): p[0] = [p[1]] + p[2] def p_small_stmt(self, p): - """small_stmt : expr_stmt - | del_stmt - | pass_stmt - | flow_stmt - | import_stmt - | global_stmt - | nonlocal_stmt - | assert_stmt + """ + small_stmt : expr_stmt + | del_stmt + | pass_stmt + | flow_stmt + | import_stmt + | global_stmt + | nonlocal_stmt + | assert_stmt """ p[0] = p[1] @@ -1158,8 +1164,9 @@ def p_small_stmt(self, p): } def p_expr_stmt_testlist_assign(self, p): - """expr_stmt : testlist_star_expr equals_yield_expr_or_testlist_list_opt - | testlist equals_yield_expr_or_testlist_list_opt + """ + expr_stmt : testlist_star_expr equals_yield_expr_or_testlist_list_opt + | testlist equals_yield_expr_or_testlist_list_opt """ p1, p2 = p[1], p[2] if isinstance(p1, ast.Tuple): @@ -1233,15 +1240,17 @@ def p_test_comma(self, p): p[0] = [p[1]] def p_comma_opt(self, p): - """comma_opt : COMMA - | empty + """ + comma_opt : COMMA + | empty """ if len(p) == 2: p[0] = p[1] def p_test_or_star_expr(self, p): - """test_or_star_expr : test - | star_expr + """ + test_or_star_expr : test + | star_expr """ p[0] = p[1] @@ -1250,8 +1259,9 @@ def p_comma_test_or_star_expr(self, p): p[0] = [p[2]] def p_testlist_star_expr(self, p): - """testlist_star_expr : test_or_star_expr comma_test_or_star_expr_list comma_opt - | test_or_star_expr comma_opt + """ + testlist_star_expr : test_or_star_expr comma_test_or_star_expr_list comma_opt + | test_or_star_expr comma_opt """ p1, p2 = p[1], p[2] if p2 is None: @@ -1277,7 +1287,8 @@ def p_testlist_star_expr(self, p): p[0] = p0 def p_augassign(self, p): - """augassign : PLUSEQUAL + """ + augassign : PLUSEQUAL | MINUSEQUAL | TIMESEQUAL | ATEQUAL @@ -1294,8 +1305,9 @@ def p_augassign(self, p): p[0] = p[1] def p_yield_expr_or_testlist(self, p): - """yield_expr_or_testlist : yield_expr - | testlist + """ + yield_expr_or_testlist : yield_expr + | testlist """ p[0] = p[1] @@ -1323,7 +1335,8 @@ def p_pass_stmt(self, p): p[0] = ast.Pass(lineno=self.lineno, col_offset=self.col) def p_flow_stmt(self, p): - """flow_stmt : break_stmt + """ + flow_stmt : break_stmt | continue_stmt | return_stmt | raise_stmt @@ -1364,14 +1377,14 @@ def p_raise_stmt_r3(self, p): p[0] = ast.Raise(exc=p[2], cause=p[4], lineno=p1.lineno, col_offset=p1.lexpos) def p_import_stmt(self, p): - """import_stmt : import_name + """ + import_stmt : import_name | import_from """ p[0] = p[1] def p_import_name(self, p): - """import_name : import_tok dotted_as_names - """ + """import_name : import_tok dotted_as_names""" p1 = p[1] p[0] = ast.Import(names=p[2], lineno=p1.lineno, col_offset=p1.lexpos) @@ -1411,8 +1424,9 @@ def p_import_from(self, p): ) def p_period_or_ellipsis(self, p): - """period_or_ellipsis : PERIOD - | ELLIPSIS + """ + period_or_ellipsis : PERIOD + | ELLIPSIS """ p[0] = p[1] @@ -1425,8 +1439,7 @@ def p_import_as_name(self, p): p[0] = ast.alias(name=p[1], asname=p[2]) def p_comma_import_as_name(self, p): - """comma_import_as_name : COMMA import_as_name - """ + """comma_import_as_name : COMMA import_as_name""" p[0] = [p[2]] def p_comma_import_as_name_tail(self, p): @@ -1463,8 +1476,9 @@ def p_period_name(self, p): p[0] = p[1] + p[2] def p_dotted_name(self, p): - """dotted_name : NAME - | NAME period_name_list + """ + dotted_name : NAME + | NAME period_name_list """ p[0] = p[1] if len(p) == 2 else p[1] + p[2] @@ -1502,14 +1516,15 @@ def p_assert_stmt(self, p): p[0] = ast.Assert(test=p2, msg=p3, lineno=p1.lineno, col_offset=p1.lexpos) def p_compound_stmt(self, p): - """compound_stmt : if_stmt - | while_stmt - | for_stmt - | try_stmt - | with_stmt - | funcdef - | classdef - | decorated + """ + compound_stmt : if_stmt + | while_stmt + | for_stmt + | try_stmt + | with_stmt + | funcdef + | classdef + | decorated """ p[0] = p[1] @@ -1531,8 +1546,9 @@ def p_else_part(self, p): p[0] = p[3] def p_if_stmt(self, p): - """if_stmt : if_tok test COLON suite elif_part_list_opt - | if_tok test COLON suite elif_part_list_opt else_part + """ + if_stmt : if_tok test COLON suite elif_part_list_opt + | if_tok test COLON suite elif_part_list_opt else_part """ p1 = p[1] lastif = ast.If( @@ -1549,8 +1565,9 @@ def p_if_stmt(self, p): p[0] = p0 def p_while_stmt(self, p): - """while_stmt : WHILE test COLON suite - | WHILE test COLON suite else_part + """ + while_stmt : WHILE test COLON suite + | WHILE test COLON suite else_part """ p5 = p[5] if len(p) > 5 else [] p[0] = [ @@ -1560,8 +1577,9 @@ def p_while_stmt(self, p): ] def p_for_stmt(self, p): - """for_stmt : for_tok exprlist IN testlist COLON suite - | for_tok exprlist IN testlist COLON suite else_part + """ + for_stmt : for_tok exprlist IN testlist COLON suite + | for_tok exprlist IN testlist COLON suite else_part """ p1, p2 = p[1], p[2] p7 = p[7] if len(p) > 7 else [] @@ -1693,8 +1711,9 @@ def p_as_expr(self, p): p[0] = p2 def p_with_item(self, p): - """with_item : test - | test as_expr + """ + with_item : test + | test as_expr """ p2 = p[2] if len(p) > 2 else None p[0] = ast.withitem(context_expr=p[1], optional_vars=p2) @@ -1718,8 +1737,9 @@ def p_except_clause(self, p): ) def p_suite(self, p): - """suite : simple_stmt - | NEWLINE INDENT stmt_list DEDENT + """ + suite : simple_stmt + | NEWLINE INDENT stmt_list DEDENT """ p[0] = p[1] if len(p) == 2 else p[3] @@ -1760,14 +1780,16 @@ def p_nodedent_many(self, p): pass def p_any_dedent_tok(self, p): - """any_dedent_tok : nodedent - | DEDENT + """ + any_dedent_tok : nodedent + | DEDENT """ pass def p_any_dedent_toks(self, p): - """any_dedent_toks : any_dedent_tok - | any_dedent_toks any_dedent_tok + """ + any_dedent_toks : any_dedent_tok + | any_dedent_toks any_dedent_tok """ pass @@ -1806,8 +1828,9 @@ def p_nonewline_many(self, p): pass def p_test_ol(self, p): - """test : or_test - | lambdef + """ + test : or_test + | lambdef """ p[0] = p[1] @@ -1818,8 +1841,9 @@ def p_test_o5(self, p): ) def p_test_nocond(self, p): - """test_nocond : or_test - | lambdef_nocond + """ + test_nocond : or_test + | lambdef_nocond """ p[0] = p[1] @@ -1925,20 +1949,22 @@ def p_comp_op_expr(self, p): } def p_comp_op_monograph(self, p): - """comp_op : LT - | GT - | EQ - | GE - | LE - | NE - | IN - | IS + """ + comp_op : LT + | GT + | EQ + | GE + | LE + | NE + | IN + | IS """ p[0] = self._comp_ops[p[1]]() def p_comp_op_digraph(self, p): - """comp_op : NOT IN - | IS NOT + """ + comp_op : NOT IN + | IS NOT """ p[0] = self._comp_ops[(p[1], p[2])]() @@ -1970,8 +1996,9 @@ def _binop_combine(self, p1, p2): return p0 def p_expr(self, p): - """expr : xor_expr - | xor_expr pipe_xor_expr_list + """ + expr : xor_expr + | xor_expr pipe_xor_expr_list """ p[0] = self._binop_combine(p[1], p[2] if len(p) > 2 else None) @@ -2027,8 +2054,9 @@ def p_shift_expr(self, p): p[0] = self._binop_combine(p[1], p[2]) def p_shift_arith_expr(self, p): - """shift_arith_expr : lshift_tok arith_expr - | rshift_tok arith_expr + """ + shift_arith_expr : lshift_tok arith_expr + | rshift_tok arith_expr """ p1 = p[1] op = ast.LShift() if p1.value == "<<" else ast.RShift() @@ -2072,8 +2100,9 @@ def p_arith_expr_many(self, p): } def p_pm_term(self, p): - """pm_term : plus_tok term - | minus_tok term + """ + pm_term : plus_tok term + | minus_tok term """ p1 = p[1] op = self._term_binops[p1.value](lineno=p1.lineno, col_offset=p1.lexpos) @@ -2101,11 +2130,12 @@ def p_term(self, p): p[0] = p0 def p_op_factor(self, p): - """op_factor : times_tok factor - | at_tok factor - | divide_tok factor - | mod_tok factor - | doublediv_tok factor + """ + op_factor : times_tok factor + | at_tok factor + | divide_tok factor + | mod_tok factor + | doublediv_tok factor """ p1 = p[1] op = self._term_binops[p1.value] @@ -2123,9 +2153,10 @@ def p_factor_power(self, p): p[0] = p[1] def p_factor_unary(self, p): - """factor : plus_tok factor - | minus_tok factor - | tilde_tok factor + """ + factor : plus_tok factor + | minus_tok factor + | tilde_tok factor """ p1 = p[1] op = self._factor_ops[p1.value]() @@ -2149,8 +2180,9 @@ def p_power(self, p): ) def p_yield_expr_or_testlist_comp(self, p): - """yield_expr_or_testlist_comp : yield_expr - | testlist_comp + """ + yield_expr_or_testlist_comp : yield_expr + | testlist_comp """ p[0] = p[1] @@ -2295,8 +2327,9 @@ def p_atom_lbrace(self, p): p[0] = p0 def p_atom_ns(self, p): - """atom : number - | string_literal_list + """ + atom : number + | string_literal_list """ p[0] = p[1] @@ -2336,28 +2369,31 @@ def p_atom_dname(self, p): p[0] = self._envvar_by_name(p[1][1:], lineno=self.lineno, col=self.col) def p_atom_fistful_of_dollars(self, p): - """atom : dollar_lbrace_tok test RBRACE - | bang_lparen_tok subproc RPAREN - | dollar_lparen_tok subproc RPAREN - | bang_lbracket_tok subproc RBRACKET - | dollar_lbracket_tok subproc RBRACKET + """ + atom : dollar_lbrace_tok test RBRACE + | bang_lparen_tok subproc RPAREN + | dollar_lparen_tok subproc RPAREN + | bang_lbracket_tok subproc RBRACKET + | dollar_lbracket_tok subproc RBRACKET """ p[0] = self._dollar_rules(p) def p_atom_bang_empty_fistful_of_dollars(self, p): - """atom : bang_lparen_tok subproc bang_tok RPAREN - | dollar_lparen_tok subproc bang_tok RPAREN - | bang_lbracket_tok subproc bang_tok RBRACKET - | dollar_lbracket_tok subproc bang_tok RBRACKET + """ + atom : bang_lparen_tok subproc bang_tok RPAREN + | dollar_lparen_tok subproc bang_tok RPAREN + | bang_lbracket_tok subproc bang_tok RBRACKET + | dollar_lbracket_tok subproc bang_tok RBRACKET """ self._append_subproc_bang_empty(p) p[0] = self._dollar_rules(p) def p_atom_bang_fistful_of_dollars(self, p): - """atom : bang_lparen_tok subproc bang_tok nocloser rparen_tok - | dollar_lparen_tok subproc bang_tok nocloser rparen_tok - | bang_lbracket_tok subproc bang_tok nocloser rbracket_tok - | dollar_lbracket_tok subproc bang_tok nocloser rbracket_tok + """ + atom : bang_lparen_tok subproc bang_tok nocloser rparen_tok + | dollar_lparen_tok subproc bang_tok nocloser rparen_tok + | bang_lbracket_tok subproc bang_tok nocloser rbracket_tok + | dollar_lbracket_tok subproc bang_tok nocloser rbracket_tok """ self._append_subproc_bang(p) p[0] = self._dollar_rules(p) @@ -2455,8 +2491,9 @@ def p_string_literal(self, p): p[0] = cls(s=s, lineno=p1.lineno, col_offset=p1.lexpos, is_raw=is_raw) def p_string_literal_list(self, p): - """string_literal_list : string_literal - | string_literal_list string_literal + """ + string_literal_list : string_literal + | string_literal_list string_literal """ if len(p) == 3: p[1].s += p[2].s @@ -2500,11 +2537,12 @@ def p_trailer_lparen(self, p): p[0] = [p[2] or dict(args=[], keywords=[], starargs=None, kwargs=None)] def p_trailer_bang_lparen(self, p): - """trailer : bang_lparen_tok macroarglist_opt rparen_tok - | bang_lparen_tok nocomma comma_tok rparen_tok - | bang_lparen_tok nocomma comma_tok WS rparen_tok - | bang_lparen_tok macroarglist comma_tok rparen_tok - | bang_lparen_tok macroarglist comma_tok WS rparen_tok + """ + trailer : bang_lparen_tok macroarglist_opt rparen_tok + | bang_lparen_tok nocomma comma_tok rparen_tok + | bang_lparen_tok nocomma comma_tok WS rparen_tok + | bang_lparen_tok macroarglist comma_tok rparen_tok + | bang_lparen_tok macroarglist comma_tok WS rparen_tok """ p1, p2, p3 = p[1], p[2], p[3] begins = [(p1.lineno, p1.lexpos + 2)] @@ -2529,14 +2567,16 @@ def p_trailer_bang_lparen(self, p): p[0] = [p0] def p_trailer_p3(self, p): - """trailer : LBRACKET subscriptlist RBRACKET - | PERIOD NAME + """ + trailer : LBRACKET subscriptlist RBRACKET + | PERIOD NAME """ p[0] = [p[2]] def p_trailer_quest(self, p): - """trailer : DOUBLE_QUESTION - | QUESTION + """ + trailer : DOUBLE_QUESTION + | QUESTION """ p[0] = [p[1]] @@ -2575,8 +2615,9 @@ def p_nocomma_tok(self, p): pass def p_any_raw_tok(self, p): - """any_raw_tok : nocomma - | COMMA + """ + any_raw_tok : nocomma + | COMMA """ pass @@ -2593,16 +2634,17 @@ def p_nocomma_part_tok(self, p): pass def p_any_nested_raw(self, p): - """any_nested_raw : LPAREN any_raw_toks_opt RPAREN - | LBRACE any_raw_toks_opt RBRACE - | LBRACKET any_raw_toks_opt RBRACKET - | AT_LPAREN any_raw_toks_opt RPAREN - | BANG_LPAREN any_raw_toks_opt RPAREN - | BANG_LBRACKET any_raw_toks_opt RBRACKET - | DOLLAR_LPAREN any_raw_toks_opt RPAREN - | DOLLAR_LBRACE any_raw_toks_opt RBRACE - | DOLLAR_LBRACKET any_raw_toks_opt RBRACKET - | ATDOLLAR_LPAREN any_raw_toks_opt RPAREN + """ + any_nested_raw : LPAREN any_raw_toks_opt RPAREN + | LBRACE any_raw_toks_opt RBRACE + | LBRACKET any_raw_toks_opt RBRACKET + | AT_LPAREN any_raw_toks_opt RPAREN + | BANG_LPAREN any_raw_toks_opt RPAREN + | BANG_LBRACKET any_raw_toks_opt RBRACKET + | DOLLAR_LPAREN any_raw_toks_opt RPAREN + | DOLLAR_LBRACE any_raw_toks_opt RBRACE + | DOLLAR_LBRACKET any_raw_toks_opt RBRACKET + | ATDOLLAR_LPAREN any_raw_toks_opt RPAREN """ pass @@ -2671,8 +2713,9 @@ def p_sliceop(self, p): p[0] = p[2] def p_expr_or_star_expr(self, p): - """expr_or_star_expr : expr - | star_expr + """ + expr_or_star_expr : expr + | star_expr """ p[0] = p[1] @@ -2713,8 +2756,9 @@ def p_testlist_single(self, p): p[0] = ensure_has_elts(p[1]) def p_testlist_many(self, p): - """testlist : test comma_test_list COMMA - | test comma_test_list + """ + testlist : test comma_test_list COMMA + | test comma_test_list """ p1 = p[1] if isinstance(p1, ast.List) or ( @@ -2792,8 +2836,9 @@ def p_dictorsetmaker_testlist(self, p): ) def p_dictorsetmaker_comp(self, p): - """dictorsetmaker : item comp_for - | test_or_star_expr comp_for + """ + dictorsetmaker : item comp_for + | test_or_star_expr comp_for """ p1 = p[1] comps = p[2].get("comps", []) @@ -2832,8 +2877,9 @@ def p_comma_argument(self, p): p[0] = [p[2]] def p_comp_iter(self, p): - """comp_iter : comp_for - | comp_if + """ + comp_iter : comp_for + | comp_if """ p[0] = p[1] @@ -3004,24 +3050,27 @@ def _subproc_cliargs(self, args, lineno=None, col=None): return cliargs def p_pipe(self, p): - """pipe : PIPE - | WS PIPE - | PIPE WS - | WS PIPE WS + """ + pipe : PIPE + | WS PIPE + | PIPE WS + | WS PIPE WS """ p[0] = ast.Str(s="|", lineno=self.lineno, col_offset=self.col) def p_amper(self, p): - """amper : AMPERSAND - | WS AMPERSAND - | AMPERSAND WS - | WS AMPERSAND WS + """ + amper : AMPERSAND + | WS AMPERSAND + | AMPERSAND WS + | WS AMPERSAND WS """ p[0] = ast.Str(s="&", lineno=self.lineno, col_offset=self.col) def p_subproc_s2(self, p): - """subproc : subproc_atoms - | subproc_atoms WS + """ + subproc : subproc_atoms + | subproc_atoms WS """ p1 = p[1] p[0] = [self._subproc_cliargs(p1, lineno=self.lineno, col=self.col)] @@ -3032,8 +3081,9 @@ def p_subproc_amper(self, p): p[0] = p1 + [p[2]] def p_subproc_pipe(self, p): - """subproc : subproc pipe subproc_atoms - | subproc pipe subproc_atoms WS + """ + subproc : subproc pipe subproc_atoms + | subproc pipe subproc_atoms WS """ p1 = p[1] if len(p1) > 1 and hasattr(p1[-2], "s") and p1[-2].s != "|": @@ -3052,8 +3102,9 @@ def p_subproc_atoms_many(self, p): p[0] = p1 def p_subproc_atoms_subshell(self, p): - """subproc_atoms : lparen_tok any_raw_tok rparen_tok - | lparen_tok any_raw_toks rparen_tok + """ + subproc_atoms : lparen_tok any_raw_tok rparen_tok + | lparen_tok any_raw_toks rparen_tok """ p1 = p[1] p3 = p[3] @@ -3071,8 +3122,9 @@ def p_subproc_atoms_subshell(self, p): p[0] = p0 def p_envvar_assign_subproc_atoms(self, p): - """subproc_atoms : envvar_assign subproc_atoms - | envvar_assign subproc_atoms WS + """ + subproc_atoms : envvar_assign subproc_atoms + | envvar_assign subproc_atoms WS """ p1, p20 = p[1], p[2][0] if hasattr(p20, "_xenvvars"): @@ -3164,8 +3216,9 @@ def p_subproc_atom_pyenv_lookup(self, p): p[0] = p0 def p_subproc_atom_pyeval(self, p): - """subproc_atom : at_lparen_tok testlist_comp RPAREN - subproc_arg_part : at_lparen_tok testlist_comp RPAREN + """ + subproc_atom : at_lparen_tok testlist_comp RPAREN + subproc_arg_part : at_lparen_tok testlist_comp RPAREN """ p1 = p[1] p0 = xonsh_call( @@ -3178,8 +3231,9 @@ def p_subproc_atom_pyeval(self, p): p[0] = p0 def p_subproc_atom_subproc_inject(self, p): - """subproc_atom : atdollar_lparen_tok subproc RPAREN - subproc_arg_part : atdollar_lparen_tok subproc RPAREN + """ + subproc_atom : atdollar_lparen_tok subproc RPAREN + subproc_arg_part : atdollar_lparen_tok subproc RPAREN """ p1, p2 = p[1], p[2] p0 = xonsh_call( @@ -3192,24 +3246,27 @@ def p_subproc_atom_subproc_inject(self, p): p[0] = p0 def p_subproc_atom_subproc_inject_bang_empty(self, p): - """subproc_atom : atdollar_lparen_tok subproc bang_tok RPAREN - subproc_arg_part : atdollar_lparen_tok subproc bang_tok RPAREN + """ + subproc_atom : atdollar_lparen_tok subproc bang_tok RPAREN + subproc_arg_part : atdollar_lparen_tok subproc bang_tok RPAREN """ self._append_subproc_bang_empty(p) self.p_subproc_atom_subproc_inject(p) def p_subproc_atom_subproc_inject_bang(self, p): - """subproc_atom : atdollar_lparen_tok subproc bang_tok nocloser rparen_tok - subproc_arg_part : atdollar_lparen_tok subproc bang_tok nocloser rparen_tok + """ + subproc_atom : atdollar_lparen_tok subproc bang_tok nocloser rparen_tok + subproc_arg_part : atdollar_lparen_tok subproc bang_tok nocloser rparen_tok """ self._append_subproc_bang(p) self.p_subproc_atom_subproc_inject(p) def p_subproc_atom_redirect(self, p): - """subproc_atom : GT - | LT - | RSHIFT - | IOREDIRECT + """ + subproc_atom : GT + | LT + | RSHIFT + | IOREDIRECT """ p0 = ast.Str(s=p[1], lineno=self.lineno, col_offset=self.col) p0._cliarg_action = "append" @@ -3329,8 +3386,9 @@ def p_envvar_assign_left(self, p): p[0] = p[1] def p_envvar_assign(self, p): - """envvar_assign : envvar_assign_left test WS - | envvar_assign_left subproc_atom WS + """ + envvar_assign : envvar_assign_left test WS + | envvar_assign_left subproc_atom WS """ p1, p2 = p[1], p[2] p[0] = ast.Dict( @@ -3347,8 +3405,9 @@ def p_envvar_assign(self, p): # def p_test_comma_combine(self, p): - """test_comma_list : test comma_test_list - | test comma_test_list COMMA + """ + test_comma_list : test comma_test_list + | test comma_test_list COMMA """ p2 = p[2] p2.insert(0, p[1]) diff --git a/xonsh/parsers/v36.py b/xonsh/parsers/v36.py index a01bc3e148..2aadd007ea 100644 --- a/xonsh/parsers/v36.py +++ b/xonsh/parsers/v36.py @@ -16,7 +16,8 @@ def __init__( yacc_debug=False, outputdir=None, ): - """Parameters + """ + Parameters ---------- lexer_optimize : bool, optional Set to false when unstable and true when lexer is stable. @@ -45,9 +46,10 @@ def __init__( ) def p_classdef_or_funcdef(self, p): - """classdef_or_funcdef : classdef - | funcdef - | async_funcdef + """ + classdef_or_funcdef : classdef + | funcdef + | async_funcdef """ p[0] = p[1] @@ -79,9 +81,10 @@ def p_atom_expr_await(self, p): p[0] = p0 def p_async_stmt(self, p): - """async_stmt : async_funcdef - | async_with_stmt - | async_for_stmt + """ + async_stmt : async_funcdef + | async_with_stmt + | async_for_stmt """ p[0] = p[1] @@ -108,8 +111,7 @@ def p_arglist_single(self, p): p[0] = p0 def p_arglist_many(self, p): - """arglist : argument comma_argument_list comma_opt - """ + """arglist : argument comma_argument_list comma_opt""" p0 = {"args": [], "keywords": []} self._set_arg(p0, p[1]) for arg in p[2]: diff --git a/xonsh/parsers/v38.py b/xonsh/parsers/v38.py index 1282df681d..6b7a18239d 100644 --- a/xonsh/parsers/v38.py +++ b/xonsh/parsers/v38.py @@ -242,8 +242,9 @@ def p_typedargslist_t11(self, p): p[0] = p0 def p_typedargslist_t12(self, p): - """typedargslist : posonlyargslist comma_opt - | posonlyargslist COMMA typedargslist + """ + typedargslist : posonlyargslist comma_opt + | posonlyargslist COMMA typedargslist """ if len(p) == 4: p0 = p[3] @@ -256,8 +257,9 @@ def p_typedargslist_t12(self, p): p[0] = p0 def p_posonlyargslist(self, p): - """posonlyargslist : tfpdef equals_test_opt COMMA DIVIDE - | tfpdef equals_test_opt comma_tfpdef_list COMMA DIVIDE""" + """ + posonlyargslist : tfpdef equals_test_opt COMMA DIVIDE + | tfpdef equals_test_opt comma_tfpdef_list COMMA DIVIDE""" p0 = ast.arguments( posonlyargs=[], args=[], @@ -392,8 +394,9 @@ def p_varargslist_v11(self, p): p[0] = p0 def p_varargslist_t12(self, p): - """varargslist : posonlyvarargslist comma_opt - | posonlyvarargslist COMMA varargslist + """ + varargslist : posonlyvarargslist comma_opt + | posonlyvarargslist COMMA varargslist """ if len(p) == 4: p0 = p[3] @@ -406,8 +409,9 @@ def p_varargslist_t12(self, p): p[0] = p0 def p_posonlyvarargslist(self, p): - """posonlyvarargslist : vfpdef equals_test_opt COMMA DIVIDE - | vfpdef equals_test_opt comma_vfpdef_list COMMA DIVIDE""" + """ + posonlyvarargslist : vfpdef equals_test_opt COMMA DIVIDE + | vfpdef equals_test_opt comma_vfpdef_list COMMA DIVIDE""" p0 = ast.arguments( posonlyargs=[], args=[], @@ -462,8 +466,9 @@ def p_argument_colonequal(self, p): ) def p_namedexpr_test(self, p): - """namedexpr_test : test - | test COLONEQUAL test + """ + namedexpr_test : test + | test COLONEQUAL test """ if len(p) == 2: p[0] = p[1] @@ -475,8 +480,9 @@ def p_namedexpr_test(self, p): ) def p_namedexpr_test_or_star_expr(self, p): - """namedexpr_test_or_star_expr : namedexpr_test - | star_expr + """ + namedexpr_test_or_star_expr : namedexpr_test + | star_expr """ p[0] = p[1] @@ -501,14 +507,16 @@ def p_elif_part(self, p): super().p_elif_part(p) def p_if_stmt(self, p): - """if_stmt : if_tok namedexpr_test COLON suite elif_part_list_opt - | if_tok namedexpr_test COLON suite elif_part_list_opt else_part + """ + if_stmt : if_tok namedexpr_test COLON suite elif_part_list_opt + | if_tok namedexpr_test COLON suite elif_part_list_opt else_part """ super().p_if_stmt(p) def p_while_stmt(self, p): - """while_stmt : WHILE namedexpr_test COLON suite - | WHILE namedexpr_test COLON suite else_part + """ + while_stmt : WHILE namedexpr_test COLON suite + | WHILE namedexpr_test COLON suite else_part """ super().p_while_stmt(p) diff --git a/xonsh/platform.py b/xonsh/platform.py index 07c13c3bee..94d54faf85 100644 --- a/xonsh/platform.py +++ b/xonsh/platform.py @@ -393,10 +393,10 @@ def windows_bash_command(): if ON_WINDOWS: class OSEnvironCasePreserving(cabc.MutableMapping): - """ Case-preserving wrapper for os.environ on Windows. - It uses nt.environ to get the correct cased keys on - initialization. It also preserves the case of any variables - add after initialization. + """Case-preserving wrapper for os.environ on Windows. + It uses nt.environ to get the correct cased keys on + initialization. It also preserves the case of any variables + add after initialization. """ def __init__(self): @@ -405,8 +405,8 @@ def __init__(self): self._upperkeys = dict((k.upper(), k) for k in nt.environ) def _sync(self): - """ Ensure that the case sensitive map of the keys are - in sync with os.environ + """Ensure that the case sensitive map of the keys are + in sync with os.environ """ envkeys = set(os.environ.keys()) for key in envkeys.difference(self._upperkeys): diff --git a/xonsh/pretty.py b/xonsh/pretty.py index f00423c7a2..1e65350eef 100644 --- a/xonsh/pretty.py +++ b/xonsh/pretty.py @@ -304,7 +304,7 @@ def flush(self): def _get_mro(obj_class): - """ Get a reasonable method resolution order of a class and its superclasses + """Get a reasonable method resolution order of a class and its superclasses for both old-style and new-style classes. """ if not hasattr(obj_class, "__mro__"): diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py index d3ca2a89ab..5742f84848 100644 --- a/xonsh/pyghooks.py +++ b/xonsh/pyghooks.py @@ -432,9 +432,9 @@ def override(self, style_dict): self.trap.update(_tokenize_style_dict(style_dict)) def enhance_colors_for_cmd_exe(self): - """ Enhance colors when using cmd.exe on windows. - When using the default style all blue and dark red colors - are changed to CYAN and intense red. + """Enhance colors when using cmd.exe on windows. + When using the default style all blue and dark red colors + are changed to CYAN and intense red. """ env = builtins.__xonsh__.env # Ensure we are not using the new Windows Terminal, ConEmu or Visual Stuio Code @@ -1317,8 +1317,8 @@ def pygments_style_by_name(name): def _monkey_patch_pygments_codes(): - """ Monky patch pygments' dict of console codes, - with new color names + """Monky patch pygments' dict of console codes, + with new color names """ if pygments_version_info() and pygments_version_info() >= (2, 4, 0): return diff --git a/xonsh/pytest_plugin.py b/xonsh/pytest_plugin.py index 8f4836ff81..74b45b3591 100644 --- a/xonsh/pytest_plugin.py +++ b/xonsh/pytest_plugin.py @@ -14,8 +14,8 @@ def pytest_configure(config): def pytest_collection_modifyitems(items): - """ Move xsh test first to work around a bug in normal - pytest cleanup. The order of tests are otherwise preserved. + """Move xsh test first to work around a bug in normal + pytest cleanup. The order of tests are otherwise preserved. """ xsh_items = [] other_items = [] @@ -28,8 +28,8 @@ def pytest_collection_modifyitems(items): def _limited_traceback(excinfo): - """ Return a formatted traceback with all the stack - from this frame (i.e __file__) up removed + """Return a formatted traceback with all the stack + from this frame (i.e __file__) up removed """ tb = extract_tb(excinfo.tb) try: diff --git a/xonsh/wizard.py b/xonsh/wizard.py index 0fbec85266..b171f2dddc 100644 --- a/xonsh/wizard.py +++ b/xonsh/wizard.py @@ -54,8 +54,7 @@ def __init__(self, message): class Question(Node): - """Asks a question and then chooses the next node based on the response. - """ + """Asks a question and then chooses the next node based on the response.""" attrs = ("question", "responses", "converter", "path") diff --git a/xontrib/free_cwd.py b/xontrib/free_cwd.py index a07568371e..1c60a61eee 100644 --- a/xontrib/free_cwd.py +++ b/xontrib/free_cwd.py @@ -17,8 +17,8 @@ def _chdir_up(path): - """ Change directory to path or if path does not exist - the first valid parent. + """Change directory to path or if path does not exist + the first valid parent. """ path = Path(path) try: @@ -30,10 +30,10 @@ def _chdir_up(path): def _cwd_release_wrapper(func): - """ Decorator for Windows to wrap the prompt function and release - the process lock on the current directory while the prompt is - displayed. This works by temporarily setting - the workdir to the users home directory. + """Decorator for Windows to wrap the prompt function and release + the process lock on the current directory while the prompt is + displayed. This works by temporarily setting + the workdir to the users home directory. """ env = builtins.__xonsh__.env if env.get("UPDATE_PROMPT_ON_KEYPRESS"): @@ -66,9 +66,9 @@ def wrapper(*args, **kwargs): def _cwd_restore_wrapper(func): - """ Decorator for Windows which will temporary restore the true working - directory. Designed to wrap completer callbacks from the - prompt_toolkit or readline. + """Decorator for Windows which will temporary restore the true working + directory. Designed to wrap completer callbacks from the + prompt_toolkit or readline. """ env = builtins.__xonsh__.env if env.get("UPDATE_PROMPT_ON_KEYPRESS"): diff --git a/xontrib/voxapi.py b/xontrib/voxapi.py index d947b3a5c8..393274e99e 100644 --- a/xontrib/voxapi.py +++ b/xontrib/voxapi.py @@ -307,8 +307,7 @@ def __contains__(self, name): return True def __iter__(self): - """List available virtual environments found in $VIRTUALENV_HOME. - """ + """List available virtual environments found in $VIRTUALENV_HOME.""" bin_, lib, inc = _subdir_names() for dirpath, dirnames, filenames in os.walk(self.venvdir): python_exec = os.path.join(dirpath, bin_, "python") @@ -319,8 +318,7 @@ def __iter__(self): dirnames.clear() def __len__(self): - """Counts known virtual environments, using the same rules as iter(). - """ + """Counts known virtual environments, using the same rules as iter().""" line = 0 for _ in self: line += 1