mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-25 12:26:44 +08:00
add pre-commit config (#6341)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
@@ -38,10 +38,7 @@ def main() -> None:
|
||||
os.environ[TYPESHED_HOME] = typeshed_location
|
||||
files_to_test = determine_files_to_test(typeshed_location=typeshed_location, paths=args.files or subdir_paths)
|
||||
run_all_tests(
|
||||
files_to_test=files_to_test,
|
||||
typeshed_location=typeshed_location,
|
||||
print_stderr=args.print_stderr,
|
||||
dry_run=args.dry_run,
|
||||
files_to_test=files_to_test, typeshed_location=typeshed_location, print_stderr=args.print_stderr, dry_run=args.dry_run
|
||||
)
|
||||
if old_typeshed_home is UNSET:
|
||||
del os.environ[TYPESHED_HOME]
|
||||
@@ -59,11 +56,7 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"--print-stderr", action="store_true", default=False, help="Print stderr every time an error is encountered."
|
||||
)
|
||||
parser.add_argument(
|
||||
"files",
|
||||
metavar="FILE",
|
||||
type=str,
|
||||
nargs="*",
|
||||
help="Files or directories to check. (Default: Check all files.)",
|
||||
"files", metavar="FILE", type=str, nargs="*", help="Files or directories to check. (Default: Check all files.)"
|
||||
)
|
||||
return parser
|
||||
|
||||
@@ -71,8 +64,7 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
def run_pytype(*, filename: str, python_version: str, typeshed_location: str) -> Optional[str]:
|
||||
"""Runs pytype, returning the stderr if any."""
|
||||
if python_version not in _LOADERS:
|
||||
options = pytype_config.Options.create(
|
||||
"", parse_pyi=True, python_version=python_version)
|
||||
options = pytype_config.Options.create("", parse_pyi=True, python_version=python_version)
|
||||
loader = load_pytd.create_loader(options)
|
||||
_LOADERS[python_version] = (options, loader)
|
||||
options, loader = _LOADERS[python_version]
|
||||
@@ -103,7 +95,7 @@ def _get_module_name(filename: str) -> str:
|
||||
"""Converts a filename {subdir}/m.n/module/foo to module.foo."""
|
||||
parts = _get_relative(filename).split(os.path.sep)
|
||||
if "@python2" in parts:
|
||||
module_parts = parts[parts.index("@python2") + 1:]
|
||||
module_parts = parts[parts.index("@python2") + 1 :]
|
||||
elif parts[0] == "stdlib":
|
||||
module_parts = parts[1:]
|
||||
else:
|
||||
@@ -157,13 +149,7 @@ def run_all_tests(*, files_to_test: Sequence[str], typeshed_location: str, print
|
||||
for i, f in enumerate(files_to_test):
|
||||
python_version = "{0.major}.{0.minor}".format(sys.version_info)
|
||||
stderr = (
|
||||
run_pytype(
|
||||
filename=f,
|
||||
python_version=python_version,
|
||||
typeshed_location=typeshed_location,
|
||||
)
|
||||
if not dry_run
|
||||
else None
|
||||
run_pytype(filename=f, python_version=python_version, typeshed_location=typeshed_location) if not dry_run else None
|
||||
)
|
||||
if stderr:
|
||||
if print_stderr:
|
||||
|
||||
Reference in New Issue
Block a user