Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass mypy and link issues #28

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions jaraco/windows/api/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 1 addition & 5 deletions jaraco/windows/api/user.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
60 changes: 31 additions & 29 deletions jaraco/windows/bugs/vista-symlink-islink-bug.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions jaraco/windows/bugs/wnetaddconnection2-error-on-64-bit.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines -7 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has been removed by c5cfffb anyway, but for posterity I wanna say that WNetAddConnection2 never actually returns anything anyway.

print('second result is', res)

r"""
Expand Down
4 changes: 2 additions & 2 deletions jaraco/windows/msie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Cookie support utilities
"""

import os
import itertools
import os


class CookieMonster(object):
"Read cookies out of a user's IE cookies file"

@property
def cookie_dir(self):
import _winreg as winreg
import winreg

key = winreg.OpenKeyEx(
winreg.HKEY_CURRENT_USER,
Expand Down
16 changes: 16 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,3 @@ formats = "zip"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143
Loading