Best Python code snippet using refurb_python
simplify_return.py
Source:simplify_return.py
...41 return False42 ```43 """44 code = 12645def get_trailing_return(node: Statement) -> Statement | None:46 match node:47 case ReturnStmt(expr=Expression()):48 return node49 case MatchStmt(50 bodies=[*bodies, Block(body=[stmt])],51 patterns=[*_, AsPattern(pattern=None)],52 ) if all(isinstance(block.body[-1], ReturnStmt) for block in bodies):53 return get_trailing_return(stmt)54 case IfStmt(55 body=[Block(body=[*_, ReturnStmt()])], else_body=Block(body=[stmt])56 ):57 return get_trailing_return(stmt)58 return None59def check(node: FuncItem, errors: list[Error]) -> None:60 match node:61 case FuncItem(body=Block(body=[*_, IfStmt() | MatchStmt() as stmt])):62 if return_node := get_trailing_return(stmt):63 name = "case _" if type(stmt) is MatchStmt else "else"64 errors.append(65 ErrorInfo(66 return_node.line,67 return_node.column,68 f"Replace `{name}: return x` with `return x`",69 )...
no_trailing_return.py
Source:no_trailing_return.py
...40 ```41 """42 code = 12543 msg: str = "Return is redundant here"44def get_trailing_return(node: Statement) -> Generator[Statement, None, None]:45 match node:46 case ReturnStmt(expr=None):47 yield node48 case MatchStmt(bodies=bodies, patterns=patterns):49 for body, pattern in zip(bodies, patterns):50 match (body.body, pattern):51 case _, AsPattern(pattern=None, name=None):52 pass53 case [ReturnStmt()], _:54 continue55 yield from get_trailing_return(body.body[-1])56 case (57 IfStmt(else_body=Block(body=[*_, stmt]))58 | WithStmt(body=Block(body=[*_, stmt]))59 ):60 yield from get_trailing_return(stmt)61 return None62def check(node: FuncItem, errors: list[Error]) -> None:63 match node:64 case FuncItem(body=Block(body=[*prev, stmt])):65 if not prev and isinstance(stmt, ReturnStmt):66 return67 for return_node in get_trailing_return(stmt):...
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!!