Best Python code snippet using refurb_python
main.py
Source:main.py
...48 return f"Refurb: v{refurb_version}\nMypy: v{mypy_version}"49@cache50def get_source_lines(filepath: str) -> list[str]:51 return Path(filepath).read_text("utf8").splitlines()52def ignored_via_comment(error: Error | str) -> bool:53 if isinstance(error, str) or not error.filename:54 return False55 line = get_source_lines(error.filename)[error.line - 1]56 if comment := re.search("# noqa(: [A-Z]{3,4}\\d{3})?$", line):57 ignore = comment.group(1)58 error_code = str(ErrorCode.from_error(type(error)))59 if not ignore or ignore[2:] == error_code:60 return True61 return False62def run_refurb(settings: Settings) -> Sequence[Error | str]:63 stderr = StringIO()64 try:65 files, opt = process_options(settings.files or [], stderr=stderr)66 except SystemExit:67 return ["refurb: " + err for err in stderr.getvalue().splitlines()]68 finally:69 stderr.close()70 opt.incremental = True71 opt.fine_grained_incremental = True72 opt.cache_fine_grained = True73 opt.allow_redefinition = True74 opt.local_partial_types = True75 if settings.python_version:76 opt.python_version = settings.python_version # pragma: no cover77 try:78 result = build(files, options=opt)79 except CompileError as e:80 return [re.sub("^mypy: ", "refurb: ", msg) for msg in e.messages]81 errors: list[Error | str] = []82 for file in files:83 if tree := result.graph[file.module].tree:84 if settings.debug:85 errors.append(str(tree))86 checks = load_checks(settings)87 visitor = RefurbVisitor(checks, settings)88 tree.accept(visitor)89 for error in visitor.errors:90 error.filename = file.path91 errors += visitor.errors92 return sorted(93 [error for error in errors if not ignored_via_comment(error)],94 key=sort_errors,95 )96def sort_errors(97 error: Error | str,98) -> tuple[str, int, int, str, int] | tuple[str, str]:99 if isinstance(error, str):100 return ("", error)101 return (102 error.filename or "",103 error.line,104 error.column,105 error.prefix,106 error.code,107 )...
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!!