54 items
NAME ↑ SIZE MODIFIED PERMS ACTIONS
.. / Parent Directory
__pycache__ — dir
2026-06-03 15:44 · rwxr-xr-x
2026-06-03 15:44 rwxr-xr-x
__init__.py — 47 B
2025-10-31 18:40 · rw-r--r--
47 B 2025-10-31 18:40 rw-r--r--
fix_apply.py — 2.29 KB
2025-10-31 18:40 · rw-r--r--
2.29 KB 2025-10-31 18:40 rw-r--r--
fix_asserts.py — 984 B
2025-10-31 18:40 · rw-r--r--
984 B 2025-10-31 18:40 rw-r--r--
fix_basestring.py — 320 B
2025-10-31 18:40 · rw-r--r--
320 B 2025-10-31 18:40 rw-r--r--
fix_buffer.py — 590 B
2025-10-31 18:40 · rw-r--r--
590 B 2025-10-31 18:40 rw-r--r--
fix_dict.py — 3.67 KB
2025-10-31 18:40 · rw-r--r--
3.67 KB 2025-10-31 18:40 rw-r--r--
fix_except.py — 3.27 KB
2025-10-31 18:40 · rw-r--r--
3.27 KB 2025-10-31 18:40 rw-r--r--
fix_exec.py — 979 B
2025-10-31 18:40 · rw-r--r--
979 B 2025-10-31 18:40 rw-r--r--
fix_execfile.py — 2 KB
2025-10-31 18:40 · rw-r--r--
2 KB 2025-10-31 18:40 rw-r--r--
fix_exitfunc.py — 2.44 KB
2025-10-31 18:40 · rw-r--r--
2.44 KB 2025-10-31 18:40 rw-r--r--
fix_filter.py — 2.7 KB
2025-10-31 18:40 · rw-r--r--
2.7 KB 2025-10-31 18:40 rw-r--r--
fix_funcattrs.py — 644 B
2025-10-31 18:40 · rw-r--r--
644 B 2025-10-31 18:40 rw-r--r--
fix_future.py — 547 B
2025-10-31 18:40 · rw-r--r--
547 B 2025-10-31 18:40 rw-r--r--
fix_getcwdu.py — 451 B
2025-10-31 18:40 · rw-r--r--
451 B 2025-10-31 18:40 rw-r--r--
fix_has_key.py — 3.12 KB
2025-10-31 18:40 · rw-r--r--
3.12 KB 2025-10-31 18:40 rw-r--r--
fix_idioms.py — 4.76 KB
2025-10-31 18:40 · rw-r--r--
4.76 KB 2025-10-31 18:40 rw-r--r--
fix_import.py — 3.18 KB
2025-10-31 18:40 · rw-r--r--
3.18 KB 2025-10-31 18:40 rw-r--r--
fix_imports.py — 5.55 KB
2025-10-31 18:40 · rw-r--r--
5.55 KB 2025-10-31 18:40 rw-r--r--
fix_imports2.py — 289 B
2025-10-31 18:40 · rw-r--r--
289 B 2025-10-31 18:40 rw-r--r--
fix_input.py — 708 B
2025-10-31 18:40 · rw-r--r--
708 B 2025-10-31 18:40 rw-r--r--
fix_intern.py — 1.12 KB
2025-10-31 18:40 · rw-r--r--
1.12 KB 2025-10-31 18:40 rw-r--r--
fix_isinstance.py — 1.57 KB
2025-10-31 18:40 · rw-r--r--
1.57 KB 2025-10-31 18:40 rw-r--r--
fix_itertools.py — 1.51 KB
2025-10-31 18:40 · rw-r--r--
1.51 KB 2025-10-31 18:40 rw-r--r--
fix_itertools_imports.py — 2.04 KB
2025-10-31 18:40 · rw-r--r--
2.04 KB 2025-10-31 18:40 rw-r--r--
fix_long.py — 476 B
2025-10-31 18:40 · rw-r--r--
476 B 2025-10-31 18:40 rw-r--r--
fix_map.py — 3.55 KB
2025-10-31 18:40 · rw-r--r--
3.55 KB 2025-10-31 18:40 rw-r--r--
fix_metaclass.py — 8 KB
2025-10-31 18:40 · rw-r--r--
8 KB 2025-10-31 18:40 rw-r--r--
fix_methodattrs.py — 606 B
2025-10-31 18:40 · rw-r--r--
606 B 2025-10-31 18:40 rw-r--r--
fix_ne.py — 571 B
2025-10-31 18:40 · rw-r--r--
571 B 2025-10-31 18:40 rw-r--r--
fix_next.py — 3.1 KB
2025-10-31 18:40 · rw-r--r--
3.1 KB 2025-10-31 18:40 rw-r--r--
fix_nonzero.py — 591 B
2025-10-31 18:40 · rw-r--r--
591 B 2025-10-31 18:40 rw-r--r--
fix_numliterals.py — 768 B
2025-10-31 18:40 · rw-r--r--
768 B 2025-10-31 18:40 rw-r--r--
fix_operator.py — 3.35 KB
2025-10-31 18:40 · rw-r--r--
3.35 KB 2025-10-31 18:40 rw-r--r--
fix_paren.py — 1.2 KB
2025-10-31 18:40 · rw-r--r--
1.2 KB 2025-10-31 18:40 rw-r--r--
fix_print.py — 2.78 KB
2025-10-31 18:40 · rw-r--r--
2.78 KB 2025-10-31 18:40 rw-r--r--
fix_raise.py — 2.86 KB
2025-10-31 18:40 · rw-r--r--
2.86 KB 2025-10-31 18:40 rw-r--r--
fix_raw_input.py — 454 B
2025-10-31 18:40 · rw-r--r--
454 B 2025-10-31 18:40 rw-r--r--
fix_reduce.py — 837 B
2025-10-31 18:40 · rw-r--r--
837 B 2025-10-31 18:40 rw-r--r--
fix_reload.py — 1.06 KB
2025-10-31 18:40 · rw-r--r--
1.06 KB 2025-10-31 18:40 rw-r--r--
fix_renames.py — 2.17 KB
2025-10-31 18:40 · rw-r--r--
2.17 KB 2025-10-31 18:40 rw-r--r--
fix_repr.py — 613 B
2025-10-31 18:40 · rw-r--r--
613 B 2025-10-31 18:40 rw-r--r--
fix_set_literal.py — 1.66 KB
2025-10-31 18:40 · rw-r--r--
1.66 KB 2025-10-31 18:40 rw-r--r--
fix_standarderror.py — 449 B
2025-10-31 18:40 · rw-r--r--
449 B 2025-10-31 18:40 rw-r--r--
fix_sys_exc.py — 1.01 KB
2025-10-31 18:40 · rw-r--r--
1.01 KB 2025-10-31 18:40 rw-r--r--
fix_throw.py — 1.54 KB
2025-10-31 18:40 · rw-r--r--
1.54 KB 2025-10-31 18:40 rw-r--r--
fix_tuple_params.py — 5.43 KB
2025-10-31 18:40 · rw-r--r--
5.43 KB 2025-10-31 18:40 rw-r--r--
fix_types.py — 1.73 KB
2025-10-31 18:40 · rw-r--r--
1.73 KB 2025-10-31 18:40 rw-r--r--
fix_unicode.py — 1.23 KB
2025-10-31 18:40 · rw-r--r--
1.23 KB 2025-10-31 18:40 rw-r--r--
fix_urllib.py — 8.17 KB
2025-10-31 18:40 · rw-r--r--
8.17 KB 2025-10-31 18:40 rw-r--r--
fix_ws_comma.py — 1.06 KB
2025-10-31 18:40 · rw-r--r--
1.06 KB 2025-10-31 18:40 rw-r--r--
fix_xrange.py — 2.63 KB
2025-10-31 18:40 · rw-r--r--
2.63 KB 2025-10-31 18:40 rw-r--r--
fix_xreadlines.py — 689 B
2025-10-31 18:40 · rw-r--r--
689 B 2025-10-31 18:40 rw-r--r--
fix_zip.py — 1.26 KB
2025-10-31 18:40 · rw-r--r--
1.26 KB 2025-10-31 18:40 rw-r--r--
ONLINE
fixes
54 items
03:14:29
TERMINAL FM
Edit
Preview
Download
Rename
Copy
Chmod
Delete
"""Adjust some old Python 2 idioms to their modern counterparts. * Change some type comparisons to isinstance() calls: type(x) == T -> isinstance(x, T) type(x) is T -> isinstance(x, T) type(x) != T -> not isinstance(x, T) type(x) is not T -> not isinstance(x, T) * Change "while 1:" into "while True:". * Change both v = list(EXPR) v.sort() foo(v) and the more general v = EXPR v.sort() foo(v) into v = sorted(EXPR) foo(v) """ # Author: Jacques Frechet, Collin Winter # Local imports from .. import fixer_base from ..fixer_util import Call, Comma, Name, Node, BlankLine, syms CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)" TYPE = "power< 'type' trailer< '(' x=any ')' > >" class FixIdioms(fixer_base.BaseFix): explicit = True # The user must ask for this fixer PATTERN = r""" isinstance=comparison< %s %s T=any > | isinstance=comparison< T=any %s %s > | while_stmt< 'while' while='1' ':' any+ > | sorted=any< any* simple_stmt< expr_stmt< id1=any '=' power< list='list' trailer< '(' (not arglist) any ')' > > > '\n' > sort= simple_stmt< power< id2=any trailer< '.' 'sort' > trailer< '(' ')' > > '\n' > next=any* > | sorted=any< any* simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' > sort= simple_stmt< power< id2=any trailer< '.' 'sort' > trailer< '(' ')' > > '\n' > next=any* > """ % (TYPE, CMP, CMP, TYPE) def match(self, node): r = super(FixIdioms, self).match(node) # If we've matched one of the sort/sorted subpatterns above, we # want to reject matches where the initial assignment and the # subsequent .sort() call involve different identifiers. if r and "sorted" in r: if r["id1"] == r["id2"]: return r return None return r def transform(self, node, results): if "isinstance" in results: return self.transform_isinstance(node, results) elif "while" in results: return self.transform_while(node, results) elif "sorted" in results: return self.transform_sort(node, results) else: raise RuntimeError("Invalid match") def transform_isinstance(self, node, results): x = results["x"].clone() # The thing inside of type() T = results["T"].clone() # The type being compared against x.prefix = "" T.prefix = " " test = Call(Name("isinstance"), [x, Comma(), T]) if "n" in results: test.prefix = " " test = Node(syms.not_test, [Name("not"), test]) test.prefix = node.prefix return test def transform_while(self, node, results): one = results["while"] one.replace(Name("True", prefix=one.prefix)) def transform_sort(self, node, results): sort_stmt = results["sort"] next_stmt = results["next"] list_call = results.get("list") simple_expr = results.get("expr") if list_call: list_call.replace(Name("sorted", prefix=list_call.prefix)) elif simple_expr: new = simple_expr.clone() new.prefix = "" simple_expr.replace(Call(Name("sorted"), [new], prefix=simple_expr.prefix)) else: raise RuntimeError("should not have reached here") sort_stmt.remove() btwn = sort_stmt.prefix # Keep any prefix lines between the sort_stmt and the list_call and # shove them right after the sorted() call. if "\n" in btwn: if next_stmt: # The new prefix should be everything from the sort_stmt's # prefix up to the last newline, then the old prefix after a new # line. prefix_lines = (btwn.rpartition("\n")[0], next_stmt[0].prefix) next_stmt[0].prefix = "\n".join(prefix_lines) else: assert list_call.parent assert list_call.next_sibling is None # Put a blank line after list_call and set its prefix. end_line = BlankLine() list_call.parent.append_child(end_line) assert list_call.next_sibling is end_line # The new prefix should be everything up to the first new line # of sort_stmt's prefix. end_line.prefix = btwn.rpartition("\n")[0]