diff --git a/jaraco/windows/api/credential.py b/jaraco/windows/api/credential.py index db1deb9..f28f822 100644 --- a/jaraco/windows/api/credential.py +++ b/jaraco/windows/api/credential.py @@ -2,18 +2,15 @@ Support for Credential Vault """ -import ctypes -from ctypes.wintypes import DWORD, LPCWSTR, BOOL, LPWSTR, FILETIME - +from __future__ import annotations -try: - from ctypes.wintypes import LPBYTE -except ImportError: - LPBYTE = ctypes.POINTER(ctypes.wintypes.BYTE) # type: ignore +import ctypes +from ctypes.wintypes import BOOL, DWORD, FILETIME, LPBYTE, LPCWSTR, LPWSTR +from typing import ClassVar class CredentialAttribute(ctypes.Structure): - _fields_ = [] # type: ignore + _fields_: ClassVar[list[tuple[str, type[ctypes._CData]]]] = [] class Credential(ctypes.Structure): diff --git a/jaraco/windows/api/user.py b/jaraco/windows/api/user.py index 936cdd2..54c164a 100644 --- a/jaraco/windows/api/user.py +++ b/jaraco/windows/api/user.py @@ -1,9 +1,5 @@ import ctypes.wintypes - -try: - from ctypes.wintypes import LPDWORD -except ImportError: - LPDWORD = ctypes.POINTER(ctypes.wintypes.DWORD) # type: ignore +from ctypes.wintypes import LPDWORD GetUserName = ctypes.windll.advapi32.GetUserNameW GetUserName.argtypes = ctypes.wintypes.LPWSTR, LPDWORD diff --git a/jaraco/windows/bugs/vista-symlink-islink-bug.py b/jaraco/windows/bugs/vista-symlink-islink-bug.py index 262cb2e..f401c62 100644 --- a/jaraco/windows/bugs/vista-symlink-islink-bug.py +++ b/jaraco/windows/bugs/vista-symlink-islink-bug.py @@ -1,29 +1,31 @@ -import os -import sys - -try: - from jaraco.windows.filesystem import symlink -except ImportError: - # a dirty reimplementation of symlink from jaraco.windows - from ctypes import windll - from ctypes.wintypes import LPWSTR, DWORD, BOOLEAN - - CreateSymbolicLink = windll.kernel32.CreateSymbolicLinkW - CreateSymbolicLink.argtypes = (LPWSTR, LPWSTR, DWORD) - CreateSymbolicLink.restype = BOOLEAN - - def symlink(link, target, target_is_directory=False): - """ - An implementation of os.symlink for Windows (Vista and greater) - """ - target_is_directory = target_is_directory or os.path.isdir(target) - CreateSymbolicLink(link, target, target_is_directory) - - -assert sys.platform in ('win32',) -os.makedirs(r'.\foo') -assert os.path.isdir(r'.\foo') - -symlink(r'.\foo_sym', r'.\foo') -assert os.path.isdir(r'.\foo_sym') -assert os.path.islink(r'.\foo_sym') # fails +import os +import sys + +try: + from jaraco.windows.filesystem import symlink +except ImportError: + # a dirty reimplementation of symlink from jaraco.windows + from ctypes import windll + from ctypes.wintypes import BOOLEAN, DWORD, LPWSTR + + CreateSymbolicLink = windll.kernel32.CreateSymbolicLinkW + CreateSymbolicLink.argtypes = (LPWSTR, LPWSTR, DWORD) + CreateSymbolicLink.restype = BOOLEAN + + # FIXME: link and target are inverted from jaraco.windows.filesystem + # https://github.com/jaraco/jaraco.windows/issues/27 + def symlink(link, target, target_is_directory=False): # type: ignore[misc] + """ + An implementation of os.symlink for Windows (Vista and greater) + """ + target_is_directory = target_is_directory or os.path.isdir(target) + CreateSymbolicLink(link, target, target_is_directory) + + +assert sys.platform in ('win32',) +os.makedirs(r'.\foo') +assert os.path.isdir(r'.\foo') + +symlink(r'.\foo_sym', r'.\foo') +assert os.path.isdir(r'.\foo_sym') +assert os.path.islink(r'.\foo_sym') # fails diff --git a/jaraco/windows/bugs/wnetaddconnection2-error-on-64-bit.py b/jaraco/windows/bugs/wnetaddconnection2-error-on-64-bit.py index d8ab55c..b3f4c57 100644 --- a/jaraco/windows/bugs/wnetaddconnection2-error-on-64-bit.py +++ b/jaraco/windows/bugs/wnetaddconnection2-error-on-64-bit.py @@ -1,12 +1,12 @@ # reported at http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/f43c2faf-3df3-4f11-9f5e-1a9101753f93 -from win32wnet import WNetAddConnection2, NETRESOURCE +from win32wnet import NETRESOURCE, WNetAddConnection2 resource = NETRESOURCE() resource.lpRemoteName = r'\\aoshi\users' username = 'jaraco' -res = WNetAddConnection2(resource, UserName=username) +res = WNetAddConnection2(resource, UserName=username) # type: ignore[func-returns-value] # python/typeshed#12595 print('first result is', res) -res = WNetAddConnection2(resource, UserName=username) +res = WNetAddConnection2(resource, UserName=username) # type: ignore[func-returns-value] # python/typeshed#12595 print('second result is', res) r""" diff --git a/jaraco/windows/msie.py b/jaraco/windows/msie.py index d413618..2451d34 100644 --- a/jaraco/windows/msie.py +++ b/jaraco/windows/msie.py @@ -3,8 +3,8 @@ Cookie support utilities """ -import os import itertools +import os class CookieMonster(object): @@ -12,7 +12,7 @@ class CookieMonster(object): @property def cookie_dir(self): - import _winreg as winreg + import winreg key = winreg.OpenKeyEx( winreg.HKEY_CURRENT_USER, diff --git a/mypy.ini b/mypy.ini index efcb8cb..45bc225 100644 --- a/mypy.ini +++ b/mypy.ini @@ -13,3 +13,19 @@ explicit_package_bases = True disable_error_code = # Disable due to many false positives overload-overlap, + +# jaraco/jaraco.ui#4 +[mypy-jaraco.ui.*] +ignore_missing_imports = True + +# jaraco/jaraco.text#17 +[mypy-jaraco.text.*] +ignore_missing_imports = True + +# jaraco/jaraco.structures#2 +[mypy-jaraco.structures.*] +ignore_missing_imports = True + +# Nowhere to raise issues and the linked SVN doesn't exist anymore +[mypy-wmi.*] +ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index 5e4a9a1..c48c1b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,3 @@ formats = "zip" [tool.setuptools_scm] - - -[tool.pytest-enabler.mypy] -# Disabled due to jaraco/skeleton#143