Commit bf04e205 by Randy Döring Committed by GitHub

mypy: fix "unused type ignore" issue on windows (#5524)

parent 6721ebe0
......@@ -8,9 +8,6 @@ import os
import sys
WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
def expanduser(path: str) -> str:
"""
Expand ~ and ~user constructions.
......@@ -44,7 +41,7 @@ def user_cache_dir(appname: str) -> str:
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
"""
if WINDOWS:
if sys.platform == "win32":
# Get the base path
path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
......@@ -93,7 +90,7 @@ def user_data_dir(appname: str, roaming: bool = False) -> str:
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
That means, by default "~/.local/share/<AppName>".
"""
if WINDOWS:
if sys.platform == "win32":
const = "CSIDL_APPDATA" if roaming else "CSIDL_LOCAL_APPDATA"
return os.path.join(os.path.normpath(_get_win_folder(const)), appname)
elif sys.platform == "darwin":
......@@ -124,7 +121,7 @@ def user_config_dir(appname: str, roaming: bool = True) -> str:
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
That means, by default "~/.config/<AppName>".
"""
if WINDOWS:
if sys.platform == "win32":
path = user_data_dir(appname, roaming=roaming)
elif sys.platform == "darwin":
path = user_data_dir(appname)
......@@ -153,7 +150,7 @@ def site_config_dirs(appname: str) -> list[str]:
Win 7: Hidden, but writeable on Win 7:
C:\ProgramData\<AppName>\
"""
if WINDOWS:
if sys.platform == "win32":
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
pathlist = [os.path.join(path, appname)]
elif sys.platform == "darwin":
......@@ -175,10 +172,9 @@ def site_config_dirs(appname: str) -> list[str]:
return pathlist
# -- Windows support functions --
if sys.platform == "win32":
def _get_win_folder_from_registry(csidl_name: str) -> str:
def _get_win_folder_from_registry(csidl_name: 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_*
......@@ -199,8 +195,7 @@ def _get_win_folder_from_registry(csidl_name: str) -> str:
directory, _type = _winreg.QueryValueEx(key, shell_folder_name)
return directory
def _get_win_folder_with_ctypes(csidl_name: str) -> str:
def _get_win_folder_with_ctypes(csidl_name: str) -> str:
csidl_const = {
"CSIDL_APPDATA": 26,
"CSIDL_COMMON_APPDATA": 35,
......@@ -208,7 +203,7 @@ def _get_win_folder_with_ctypes(csidl_name: str) -> str:
}[csidl_name]
buf = ctypes.create_unicode_buffer(1024)
windll = ctypes.windll # type: ignore[attr-defined]
windll = ctypes.windll
windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
# Downgrade to short path name if have highbit chars. See
......@@ -221,8 +216,6 @@ def _get_win_folder_with_ctypes(csidl_name: str) -> str:
return buf.value
if WINDOWS:
try:
import ctypes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment