Skip to content

Commit

Permalink
Merge branch 'mr/leger/master/fix-mypy-errors-on-windows' into 'master'
Browse files Browse the repository at this point in the history
Fixed some check warning on Windows

Closes #37

See merge request it/e3-core!94
  • Loading branch information
grouigrokon committed Jan 23, 2025
2 parents 488e453 + 40fba35 commit 9be339e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/e3/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@

class E3ZipInfo(zipfile.ZipInfo):
@classmethod
def from_file(cls, *args, **kwargs):
def from_file(cls, *args, **kwargs): # type: ignore[no-untyped-def]
result = super().from_file(*args, **kwargs)
result.external_attr = (0o555 << 16) | result.external_attr
return result

zipfile.ZipInfo = E3ZipInfo
zipfile.ZipInfo = E3ZipInfo # type: ignore[misc]


class E3ZipFile(zipfile.ZipFile):
Expand Down
14 changes: 8 additions & 6 deletions src/e3/os/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def df(path: str | Path, full: bool = False) -> int | tuple:
if sys.platform == "win32": # unix: no cover
import ctypes

c_path = ctypes.c_wchar_p(path)
c_path = ctypes.c_wchar_p(str(path))
GetDiskFreeSpaceEx: Callable = ctypes.WINFUNCTYPE(
ctypes.c_int,
ctypes.c_wchar_p,
Expand All @@ -176,13 +176,13 @@ def df(path: str | Path, full: bool = False) -> int | tuple:
((1, "path"), (2, "freeuserspace"), (2, "totalspace"), (2, "freespace")),
)

def GetDiskFreeSpaceEx_errcheck(result, func, args):
def GetDiskFreeSpaceEx_errcheck(result, func, args): # type: ignore[no-untyped-def]
del func
if not result: # defensive code
raise ctypes.WinError()
return (args[1].value, args[2].value, args[3].value)
return args[1].value, args[2].value, args[3].value

GetDiskFreeSpaceEx.errcheck = GetDiskFreeSpaceEx_errcheck
GetDiskFreeSpaceEx.errcheck = GetDiskFreeSpaceEx_errcheck # type: ignore[attr-defined]
_, total, free = GetDiskFreeSpaceEx(c_path)
used = total - free
else: # windows: no cover
Expand Down Expand Up @@ -347,8 +347,10 @@ def readlink(filename: str | Path) -> str:
# This might be a WSL link
from e3.os.windows.fs import NTFile

f = NTFile(filename)
return f.wsl_reparse_link_target()
reparsed_link: str | None = NTFile(filename).wsl_reparse_link_target()
if reparsed_link is not None:
return reparsed_link
raise
else:
raise

Expand Down
2 changes: 1 addition & 1 deletion src/e3/os/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def fetch_system_data(cls) -> None:

# Fetch linux distribution info on linux OS
if cls.uname.system == "Linux": # linux-only
import distro
import distro # type: ignore[import-not-found]

cls.ld_info = {
"name": distro.name(),
Expand Down
1 change: 1 addition & 0 deletions src/e3/os/windows/native_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def __init__(self, name: UnicodeString, parent: HANDLE | None = None):
class NT:
FindFirstFile = None
FindClose = None
FsControlFile = None
Sleep = None
GetVolumePathName = None
SetInformationFile = None
Expand Down
2 changes: 1 addition & 1 deletion src/e3/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def is_console() -> bool:
from msvcrt import get_osfhandle
from e3.os.windows.object import object_name

stdin_name = object_name(get_osfhandle(stdin_fd))
stdin_name = object_name(get_osfhandle(stdin_fd)) # type: ignore[arg-type]
if re.match(r"\\Device\\NamedPipe\\(cygwin|msys).*-pty.*$", stdin_name):
return True
else:
Expand Down
2 changes: 1 addition & 1 deletion src/e3/vcs/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def is_unix_svn(cls) -> bool:
return True
else:
svn_version = e3.os.process.Run(["svn", "--version"]).out
if "cygwin" in svn_version:
if svn_version is not None and "cygwin" in svn_version:
return True
else:
return False
Expand Down

0 comments on commit 9be339e

Please sign in to comment.