mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-27 03:18:39 -06:00
mypy passes with check_untyped_defs
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
from pre_commit.languages import conda
|
||||
from pre_commit.languages import docker
|
||||
from pre_commit.languages import docker_image
|
||||
@@ -13,6 +16,7 @@ from pre_commit.languages import script
|
||||
from pre_commit.languages import swift
|
||||
from pre_commit.languages import system
|
||||
|
||||
|
||||
# A language implements the following constant and functions in its module:
|
||||
#
|
||||
# # Use None for no environment
|
||||
@@ -49,7 +53,7 @@ from pre_commit.languages import system
|
||||
# (returncode, output)
|
||||
# """
|
||||
|
||||
languages = {
|
||||
languages: Dict[str, Any] = {
|
||||
'conda': conda,
|
||||
'docker': docker,
|
||||
'docker_image': docker_image,
|
||||
|
||||
@@ -2,6 +2,7 @@ import contextlib
|
||||
import os
|
||||
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import SubstitutionT
|
||||
from pre_commit.envcontext import UNSET
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
@@ -18,7 +19,7 @@ def get_env_patch(env):
|
||||
# they can be in $CONDA_PREFIX/bin, $CONDA_PREFIX/Library/bin,
|
||||
# $CONDA_PREFIX/Scripts and $CONDA_PREFIX. Whereas the latter only
|
||||
# seems to be used for python.exe.
|
||||
path = (os.path.join(env, 'bin'), os.pathsep, Var('PATH'))
|
||||
path: SubstitutionT = (os.path.join(env, 'bin'), os.pathsep, Var('PATH'))
|
||||
if os.name == 'nt': # pragma: no cover (platform specific)
|
||||
path = (env, os.pathsep) + path
|
||||
path = (os.path.join(env, 'Scripts'), os.pathsep) + path
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import hashlib
|
||||
import os
|
||||
from typing import Tuple
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import five
|
||||
@@ -42,7 +43,7 @@ def assert_docker_available(): # pragma: windows no cover
|
||||
def build_docker_image(prefix, **kwargs): # pragma: windows no cover
|
||||
pull = kwargs.pop('pull')
|
||||
assert not kwargs, kwargs
|
||||
cmd = (
|
||||
cmd: Tuple[str, ...] = (
|
||||
'docker', 'build',
|
||||
'--tag', docker_tag(prefix),
|
||||
'--label', PRE_COMMIT_LABEL,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import contextlib
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -64,7 +65,8 @@ def _find_by_sys_executable():
|
||||
return None
|
||||
|
||||
|
||||
def _get_default_version(): # pragma: no cover (platform dependent)
|
||||
@functools.lru_cache(maxsize=1)
|
||||
def get_default_version(): # pragma: no cover (platform dependent)
|
||||
# First attempt from `sys.executable` (or the realpath)
|
||||
exe = _find_by_sys_executable()
|
||||
if exe:
|
||||
@@ -86,15 +88,6 @@ def _get_default_version(): # pragma: no cover (platform dependent)
|
||||
return C.DEFAULT
|
||||
|
||||
|
||||
def get_default_version():
|
||||
# TODO: when dropping python2, use `functools.lru_cache(maxsize=1)`
|
||||
try:
|
||||
return get_default_version.cached_version
|
||||
except AttributeError:
|
||||
get_default_version.cached_version = _get_default_version()
|
||||
return get_default_version()
|
||||
|
||||
|
||||
def _sys_executable_matches(version):
|
||||
if version == 'python':
|
||||
return True
|
||||
|
||||
@@ -5,6 +5,7 @@ import tarfile
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import PatchesT
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import CalledProcessError
|
||||
@@ -18,7 +19,7 @@ healthy = helpers.basic_healthy
|
||||
|
||||
|
||||
def get_env_patch(venv, language_version): # pragma: windows no cover
|
||||
patches = (
|
||||
patches: PatchesT = (
|
||||
('GEM_HOME', os.path.join(venv, 'gems')),
|
||||
('RBENV_ROOT', venv),
|
||||
('BUNDLE_IGNORE_CONFIG', '1'),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import contextlib
|
||||
import os.path
|
||||
from typing import Set
|
||||
from typing import Tuple
|
||||
|
||||
import toml
|
||||
|
||||
@@ -71,7 +73,7 @@ def install_environment(prefix, version, additional_dependencies):
|
||||
_add_dependencies(prefix.path('Cargo.toml'), lib_deps)
|
||||
|
||||
with clean_path_on_failure(directory):
|
||||
packages_to_install = {('--path', '.')}
|
||||
packages_to_install: Set[Tuple[str, ...]] = {('--path', '.')}
|
||||
for cli_dep in cli_deps:
|
||||
cli_dep = cli_dep[len('cli:'):]
|
||||
package, _, version = cli_dep.partition(':')
|
||||
|
||||
Reference in New Issue
Block a user