From 49737605d791d24f789f57d5dcc232f9eeb6fa89 Mon Sep 17 00:00:00 2001 From: Monica Baluna Date: Fri, 26 Oct 2018 18:33:45 +0300 Subject: [PATCH 1/2] Add mypy annotations for utils/appdirs --- src/pip/_internal/utils/appdirs.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pip/_internal/utils/appdirs.py b/src/pip/_internal/utils/appdirs.py index cc96f9841ee..f036ca1c53e 100644 --- a/src/pip/_internal/utils/appdirs.py +++ b/src/pip/_internal/utils/appdirs.py @@ -10,9 +10,16 @@ from pip._vendor.six import PY2, text_type from pip._internal.utils.compat import WINDOWS, expanduser +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from typing import ( # noqa: F401 + List, Union + ) def user_cache_dir(appname): + # type: (str) -> str r""" Return full path to the user-specific cache dir for this application. @@ -61,6 +68,7 @@ def user_cache_dir(appname): def user_data_dir(appname, roaming=False): + # type: (str, bool) -> str r""" Return full path to the user-specific data dir for this application. @@ -113,6 +121,7 @@ def user_data_dir(appname, roaming=False): def user_config_dir(appname, roaming=True): + # type: (str, bool) -> str """Return full path to the user-specific config dir for this application. "appname" is the name of application. @@ -146,6 +155,7 @@ def user_config_dir(appname, roaming=True): # for the discussion regarding site_config_dirs locations # see def site_config_dirs(appname): + # type: (str) -> List[str] r"""Return a list of potential user-shared config dirs for this application. "appname" is the name of application. @@ -186,6 +196,7 @@ def site_config_dirs(appname): # -- Windows support functions -- def _get_win_folder_from_registry(csidl_name): + # type: (str) -> str """ This is a fallback technique at best. I'm not sure if using the registry for this guarantees us the correct answer for all CSIDL_* @@ -208,6 +219,7 @@ def _get_win_folder_from_registry(csidl_name): def _get_win_folder_with_ctypes(csidl_name): + # type: (str) -> str csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, @@ -241,6 +253,7 @@ def _get_win_folder_with_ctypes(csidl_name): def _win_path_to_bytes(path): + # type: (str) -> Union[bytes, str] """Encode Windows paths to bytes. Only used on Python 2. Motivation is to be consistent with other operating systems where paths From eed9489a31bd0d40ff2ea168837c6e96c9395f1e Mon Sep 17 00:00:00 2001 From: mbaluna <44498973+mbaluna@users.noreply.github.com> Date: Wed, 31 Oct 2018 10:05:52 +0000 Subject: [PATCH 2/2] Remove win_path_to_bytes annotation --- src/pip/_internal/utils/appdirs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pip/_internal/utils/appdirs.py b/src/pip/_internal/utils/appdirs.py index f036ca1c53e..9af9fa7b582 100644 --- a/src/pip/_internal/utils/appdirs.py +++ b/src/pip/_internal/utils/appdirs.py @@ -253,7 +253,6 @@ def _get_win_folder_with_ctypes(csidl_name): def _win_path_to_bytes(path): - # type: (str) -> Union[bytes, str] """Encode Windows paths to bytes. Only used on Python 2. Motivation is to be consistent with other operating systems where paths