Best Python code snippet using refurb_python
no_with_assign.py
Source:no_with_assign.py  
...31    """32    code = 12733    msg: str = "This variable is redeclared later, and can be removed here"34def check(node: Block | MypyFile, errors: list[Error]) -> None:35    check_block_like(check_stmts, node, errors)36def check_stmts(body: list[Statement], errors: list[Error]) -> None:37    assign: AssignmentStmt | None = None38    for stmt in body:39        if assign:40            match stmt:41                case WithStmt(42                    body=Block(43                        body=[AssignmentStmt(lvalues=[NameExpr() as name])]44                    ),45                    expr=resources,46                ) if (47                    name.fullname48                    and name.fullname49                    == assign.lvalues[0].fullname  # type: ignore...use_tuple_swap.py
Source:use_tuple_swap.py  
...20    """21    code = 12822    msg: str = "Use tuple unpacking instead of temporary variables to swap values"  # noqa: E50123def check(node: Block | MypyFile, errors: list[Error]) -> None:24    check_block_like(check_stmts, node, errors)25def check_stmts(stmts: list[Statement], errors: list[Error]) -> None:26    assignments = []27    for stmt in stmts:28        if isinstance(stmt, AssignmentStmt):29            assignments.append(stmt)30        else:31            assignments = []32        if len(assignments) == 3:33            match assignments:34                case [35                    AssignmentStmt(36                        lvalues=[NameExpr() as a], rvalue=NameExpr() as b37                    ),38                    AssignmentStmt(...list_extend.py
Source:list_extend.py  
...37    line: int = 038    column: int = 039    did_error: bool = False40def check(node: Block | MypyFile, errors: list[Error]) -> None:41    check_block_like(check_stmts, node, errors)42def check_stmts(stmts: list[Statement], errors: list[Error]) -> None:43    last = Last()44    for stmt in stmts:45        match stmt:46            case ExpressionStmt(47                expr=CallExpr(48                    callee=MemberExpr(expr=NameExpr(name=name), name="append")49                )50            ):51                if not last.did_error and name == last.name:52                    errors.append(ErrorInfo(last.line, last.column))53                    last.did_error = True54                last.name = name55                last.line = stmt.line...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
