From dea4dd1dc162cb8e6bff31ee4d135bdf17d82c9b Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 12 Mar 2024 01:42:51 -0400 Subject: [PATCH] `pywin32`: Correctly reference `TimeType` aka `pywintypes.datetime` (#11577) * Correctly reference TimeType * PyUnicode is UnicodeType --- stubs/pywin32/_win32typing.pyi | 52 ++++++++------------------ stubs/pywin32/pythoncom.pyi | 4 +- stubs/pywin32/win32/lib/pywintypes.pyi | 18 +++++---- stubs/pywin32/win32/win32api.pyi | 8 ++-- stubs/pywin32/win32/win32file.pyi | 12 +++--- stubs/pywin32/win32/win32inet.pyi | 6 +-- stubs/pywin32/win32/win32security.pyi | 8 ++-- 7 files changed, 44 insertions(+), 64 deletions(-) diff --git a/stubs/pywin32/_win32typing.pyi b/stubs/pywin32/_win32typing.pyi index 444f98f95..9f96f7b9f 100644 --- a/stubs/pywin32/_win32typing.pyi +++ b/stubs/pywin32/_win32typing.pyi @@ -4,6 +4,8 @@ from collections.abc import Iterable from typing import Literal, final, overload from typing_extensions import Self, TypeAlias, deprecated +from win32.lib.pywintypes import TimeType + class ArgNotFound: ... class PyOleEmpty: ... class PyOleMissing: ... @@ -306,9 +308,9 @@ class PyCERT_CONTEXT: @property def Issuer(self) -> str: ... @property - def NotBefore(self) -> PyTime: ... + def NotBefore(self) -> TimeType: ... @property - def NotAfter(self) -> PyTime: ... + def NotAfter(self) -> TimeType: ... @property def SignatureAlgorithm(self): ... @property @@ -398,7 +400,7 @@ class PyCREDENTIAL: @property def Comment(self) -> str: ... @property - def LastWritten(self) -> PyTime: ... + def LastWritten(self) -> TimeType: ... @property def CredentialBlob(self) -> str: ... @property @@ -832,10 +834,6 @@ class PyDLGITEMTEMPLATE: ... class PyDLGTEMPLATE: ... class PyDS_HANDLE: ... class PyDS_NAME_RESULT_ITEM: ... - -class PyDateTime: - def Format(self): ... - class PyDialogTemplate: ... class PyEVTLOG_HANDLE: ... class PyEVT_HANDLE: ... @@ -847,9 +845,9 @@ class PyEventLogRecord: @property def RecordNumber(self) -> int: ... @property - def TimeGenerated(self) -> PyTime: ... + def TimeGenerated(self) -> TimeType: ... @property - def TimeWritten(self) -> PyTime: ... + def TimeWritten(self) -> TimeType: ... @property def EventID(self) -> int: ... @property @@ -1703,25 +1701,6 @@ class PyTRUSTEE: class PyTS_HANDLE: ... -class PyTime: - @property - def year(self): ... - @property - def month(self): ... - @property - def weekday(self): ... - @property - def day(self): ... - @property - def hour(self): ... - @property - def minute(self): ... - @property - def second(self): ... - @property - def msec(self): ... - def Format(self, _format: str, /) -> str: ... - class PyUSER_INFO_0: @property def name(self) -> str: ... @@ -2106,7 +2085,6 @@ class PyUSE_INFO_3: @property def flags(self): ... -class PyUnicode: ... class PyUrlCacheHANDLE: ... class PyWAVEFORMATEX: @@ -2859,7 +2837,7 @@ class PyIADsUser: def get_AccountDisabled(self): ... def put_AccountDisabled(self, val, /) -> None: ... def get_AccountExpirationDate(self): ... - def put_AccountExpirationDate(self, val: PyTime, /) -> None: ... + def put_AccountExpirationDate(self, val: TimeType, /) -> None: ... def get_BadLoginAddress(self): ... def get_BadLoginCount(self): ... def get_Department(self): ... @@ -4260,7 +4238,7 @@ class PyIPropertyStorage: def Commit(self, CommitFlags, /) -> None: ... def Revert(self) -> None: ... def Enum(self) -> PyIEnumSTATPROPSTG: ... - def SetTimes(self, ctime: PyTime, atime: PyTime, mtime: PyTime, /) -> None: ... + def SetTimes(self, ctime: TimeType, atime: TimeType, mtime: TimeType, /) -> None: ... def SetClass(self, clsid: PyIID, /) -> None: ... def Stat(self): ... @@ -4360,14 +4338,14 @@ class PyIScheduledWorkItem: def GetTriggerCount(self): ... def GetTrigger(self, iTrigger, /) -> PyITaskTrigger: ... def GetTriggerString(self): ... - def GetRunTimes(self, Count, Begin: PyTime, End: PyTime, /) -> tuple[PyTime, Incomplete, Incomplete, Incomplete]: ... - def GetNextRunTime(self) -> PyTime: ... + def GetRunTimes(self, Count, Begin: TimeType, End: TimeType, /) -> tuple[TimeType, Incomplete, Incomplete, Incomplete]: ... + def GetNextRunTime(self) -> TimeType: ... def SetIdleWait(self, wIdleMinutes, wDeadlineMinutes, /) -> None: ... def GetIdleWait(self) -> tuple[Incomplete, Incomplete]: ... def Run(self) -> None: ... def Terminate(self) -> None: ... def EditWorkItem(self, hParent: int, dwReserved, /) -> None: ... - def GetMostRecentRunTime(self) -> PyTime: ... + def GetMostRecentRunTime(self) -> TimeType: ... def GetStatus(self): ... def GetExitCode(self) -> tuple[Incomplete, Incomplete]: ... def SetComment(self, Comment, /) -> None: ... @@ -4469,7 +4447,7 @@ class PyIShellItem2: def Update(self, BindCtx: Incomplete | None = ..., /) -> None: ... def GetProperty(self, key: PyPROPERTYKEY, /): ... def GetCLSID(self, key: PyPROPERTYKEY, /) -> PyIID: ... - def GetFileTime(self, key: PyPROPERTYKEY, /) -> PyTime: ... + def GetFileTime(self, key: PyPROPERTYKEY, /) -> TimeType: ... def GetInt32(self, key: PyPROPERTYKEY, /): ... def GetString(self, key: PyPROPERTYKEY, /): ... def GetUInt32(self, key: PyPROPERTYKEY, /): ... @@ -4489,7 +4467,7 @@ class PyIShellItemResources: def GetAttributes(self) -> None: ... def GetSize(self): ... def GetTimes(self) -> None: ... - def SetTimes(self, pftCreation: PyTime, pftWrite: PyTime, pftAccess: PyTime, /) -> None: ... + def SetTimes(self, pftCreation: TimeType, pftWrite: TimeType, pftAccess: TimeType, /) -> None: ... def GetResourceDescription(self, pcsir: PySHELL_ITEM_RESOURCE, /) -> None: ... def EnumResources(self) -> PyIEnumResources: ... def SupportsResource(self, pcsir: PySHELL_ITEM_RESOURCE, /): ... @@ -4579,7 +4557,7 @@ class PyIStorage: ) -> PyIEnumSTATSTG: ... def DestroyElement(self, name: str, /) -> None: ... def RenameElement(self, OldName, NewName, /) -> None: ... - def SetElementTimes(self, name, ctime: PyTime, atime: PyTime, mtime: PyTime, /) -> None: ... + def SetElementTimes(self, name, ctime: TimeType, atime: TimeType, mtime: TimeType, /) -> None: ... def SetClass(self, clsid: PyIID, /) -> None: ... def SetStateBits(self, grfStateBits, grfMask, /) -> None: ... def Stat(self, grfStatFlag, /) -> STATSTG: ... diff --git a/stubs/pywin32/pythoncom.pyi b/stubs/pywin32/pythoncom.pyi index e2c719491..de4a15002 100644 --- a/stubs/pywin32/pythoncom.pyi +++ b/stubs/pywin32/pythoncom.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete from typing_extensions import TypeAlias, deprecated import _win32typing -from win32.lib.pywintypes import com_error as com_error +from win32.lib.pywintypes import TimeType, com_error as com_error error: TypeAlias = com_error # noqa: Y042 @@ -72,7 +72,7 @@ def MakePyFactory(iid: _win32typing.PyIID, /) -> _win32typing.PyIClassFactory: . @deprecated("Use pywintypes.IID() instead.") def MakeIID(iidString: str, is_bytes: bool = ..., /) -> _win32typing.PyIID: ... @deprecated("Use pywintypes.Time() instead.") -def MakeTime(timeRepr, /) -> _win32typing.PyTime: ... +def MakeTime(timeRepr, /) -> TimeType: ... def MkParseDisplayName( displayName: str, bindCtx: _win32typing.PyIBindCtx | None = ..., / ) -> tuple[_win32typing.PyIMoniker, Incomplete, _win32typing.PyIBindCtx]: ... diff --git a/stubs/pywin32/win32/lib/pywintypes.pyi b/stubs/pywin32/win32/lib/pywintypes.pyi index 29b26e631..87db6d51d 100644 --- a/stubs/pywin32/win32/lib/pywintypes.pyi +++ b/stubs/pywin32/win32/lib/pywintypes.pyi @@ -1,9 +1,9 @@ -# Can't generate with stubgen because: -# "KeyError: 'pywintypes'" +# Can't generate with stubgen because `import pywintypes` must be called first. +# Otherwise you get the error: "KeyError: 'pywintypes'" from _typeshed import Incomplete from datetime import datetime -from typing import Literal, NoReturn, overload -from typing_extensions import Never, deprecated +from typing import ClassVar, Literal, NoReturn, overload +from typing_extensions import Never, TypeAlias, deprecated import _win32typing @@ -14,7 +14,8 @@ class error(Exception): def __init__(self, winerror: int, funcname: str, strerror: str, /): ... class com_error(Exception): ... -class UnicodeType(str): ... + +UnicodeType: TypeAlias = str class HANDLEType: def __init__(self, *args: Never) -> NoReturn: ... @@ -25,18 +26,19 @@ class HANDLEType: def Detach(self) -> None: ... def __int__(self) -> int: ... -class TimeType(datetime): +class TimeType(datetime): # aka: PyTime, PyDateTime + __name__: ClassVar[str] = "datetime" Format = datetime.strftime IIDType = _win32typing.PyIID -def DosDateTimeToTime() -> _win32typing.PyTime: ... +def DosDateTimeToTime() -> TimeType: ... def Unicode() -> str: ... def UnicodeFromRaw(_str: str, /) -> str: ... def IsTextUnicode(_str: str, flags, /) -> tuple[Incomplete, Incomplete]: ... def OVERLAPPED() -> _win32typing.PyOVERLAPPED: ... def IID(iidString: str, is_bytes: bool = ..., /) -> _win32typing.PyIID: ... -def Time(timeRepr, /) -> _win32typing.PyTime: ... +def Time(timeRepr, /) -> TimeType: ... def CreateGuid() -> _win32typing.PyIID: ... def ACL(bufSize: int = ..., /) -> _win32typing.PyACL: ... def SID(buffer, idAuthority, subAuthorities, bufSize=..., /) -> _win32typing.PySID: ... diff --git a/stubs/pywin32/win32/win32api.pyi b/stubs/pywin32/win32/win32api.pyi index 759f5c160..86390d4ee 100644 --- a/stubs/pywin32/win32/win32api.pyi +++ b/stubs/pywin32/win32/win32api.pyi @@ -4,7 +4,7 @@ from typing import TypedDict from typing_extensions import deprecated import _win32typing -from win32.lib.pywintypes import error as error +from win32.lib.pywintypes import TimeType, error as error class _MonitorInfo(TypedDict): Monitor: tuple[int, int, int, int] @@ -85,7 +85,7 @@ def GetCurrentThreadId(): ... def GetCurrentProcessId(): ... def GetCurrentProcess() -> int: ... def GetConsoleTitle() -> str: ... -def GetDateFormat(locale, flags, time: _win32typing.PyTime, _format: str, /) -> str: ... +def GetDateFormat(locale, flags, time: TimeType, _format: str, /) -> str: ... def GetDiskFreeSpace(rootPath: str, /): ... def GetDiskFreeSpaceEx(rootPath: str, /) -> tuple[int, int, int]: ... def GetDllDirectory() -> str: ... @@ -134,7 +134,7 @@ def GetTempFileName(path: str, prefix: str, nUnique, /): ... def GetTempPath() -> str: ... def GetThreadLocale(): ... def GetTickCount() -> int: ... -def GetTimeFormat(locale, flags, time: _win32typing.PyTime, _format: str, /) -> str: ... +def GetTimeFormat(locale, flags, time: TimeType, _format: str, /) -> str: ... def GetTimeZoneInformation(times_as_tuples: bool = ..., /): ... def GetVersion(): ... def GetVersionEx(_format: int = ..., /): ... @@ -223,7 +223,7 @@ def SetErrorMode(errorMode, /): ... def SetFileAttributes(pathName: str, attrs, /): ... def SetLastError(): ... def SetSysColors(Elements, RgbValues, /) -> None: ... -def SetLocalTime(SystemTime: _win32typing.PyTime, /) -> None: ... +def SetLocalTime(SystemTime: TimeType, /) -> None: ... def SetSystemTime(year, month, dayOfWeek, day, hour, minute, second, millseconds, /): ... def SetClassLong(hwnd: int, offset, val, /): ... @deprecated("This function is obsolete, use `win32api.SetClassLong` instead") diff --git a/stubs/pywin32/win32/win32file.pyi b/stubs/pywin32/win32/win32file.pyi index 7dd4efc5c..c186b12a5 100644 --- a/stubs/pywin32/win32/win32file.pyi +++ b/stubs/pywin32/win32/win32file.pyi @@ -4,7 +4,7 @@ from typing import overload from typing_extensions import deprecated import _win32typing -from win32.lib.pywintypes import error as error +from win32.lib.pywintypes import TimeType, error as error def AreFileApisANSI(): ... def CancelIo(handle: int, /) -> None: ... @@ -44,13 +44,13 @@ def GetDriveTypeW(rootPathName: str, /): ... def GetFileAttributes(fileName: str, /): ... def GetFileAttributesW(fileName: str, /): ... def GetFileTime( - handle: int, creationTime: _win32typing.PyTime, accessTime: _win32typing.PyTime, writeTime: _win32typing.PyTime, / -) -> tuple[_win32typing.PyTime, _win32typing.PyTime, _win32typing.PyTime]: ... + handle: int, creationTime: TimeType, accessTime: TimeType, writeTime: TimeType, / +) -> tuple[TimeType, TimeType, TimeType]: ... def SetFileTime( File: int, - CreationTime: _win32typing.PyTime | None = ..., - LastAccessTime: _win32typing.PyTime | None = ..., - LastWriteTime: _win32typing.PyTime | None = ..., + CreationTime: TimeType | None = ..., + LastAccessTime: TimeType | None = ..., + LastWriteTime: TimeType | None = ..., UTCTimes: bool = ..., ) -> None: ... def GetFileInformationByHandle(handle: int, /): ... diff --git a/stubs/pywin32/win32/win32inet.pyi b/stubs/pywin32/win32/win32inet.pyi index e906d86a0..3ccc4d979 100644 --- a/stubs/pywin32/win32/win32inet.pyi +++ b/stubs/pywin32/win32/win32inet.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete import _win32typing -from win32.lib.pywintypes import error as error +from win32.lib.pywintypes import TimeType, error as error def InternetSetCookie(url: str, lpszCookieName: str, data: str, /) -> None: ... def InternetGetCookie(Url: str, CookieName: str, /) -> str: ... @@ -52,8 +52,8 @@ def CommitUrlCacheEntry( UrlName, LocalFileName, CacheEntryType, - ExpireTime: _win32typing.PyTime | None = ..., - LastModifiedTime: _win32typing.PyTime | None = ..., + ExpireTime: TimeType | None = ..., + LastModifiedTime: TimeType | None = ..., HeaderInfo: Incomplete | None = ..., OriginalUrl: Incomplete | None = ..., ): ... diff --git a/stubs/pywin32/win32/win32security.pyi b/stubs/pywin32/win32/win32security.pyi index 74e491bf6..98309da32 100644 --- a/stubs/pywin32/win32/win32security.pyi +++ b/stubs/pywin32/win32/win32security.pyi @@ -3,7 +3,7 @@ from typing import overload from typing_extensions import deprecated import _win32typing -from win32.lib.pywintypes import error as error +from win32.lib.pywintypes import TimeType, error as error def DsGetSpn( ServiceType, @@ -147,11 +147,11 @@ def LsaGetLogonSessionData(LogonId: int, /) -> tuple[Incomplete, ...]: ... @deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead") def AcquireCredentialsHandle( Principal, Package, CredentialUse, LogonID: tuple[int, int], AuthData, / -) -> tuple[_win32typing.PyCredHandle, _win32typing.PyTime]: ... +) -> tuple[_win32typing.PyCredHandle, TimeType]: ... @overload def AcquireCredentialsHandle( Principal, Package, CredentialUse, LogonID: int | None, AuthData, / -) -> tuple[_win32typing.PyCredHandle, _win32typing.PyTime]: ... +) -> tuple[_win32typing.PyCredHandle, TimeType]: ... def InitializeSecurityContext( Credential: _win32typing.PyCredHandle, Context: _win32typing.PyCtxtHandle, @@ -162,7 +162,7 @@ def InitializeSecurityContext( NewContext: _win32typing.PyCtxtHandle, pOutput: _win32typing.PySecBufferDesc, /, -) -> tuple[Incomplete, Incomplete, _win32typing.PyTime]: ... +) -> tuple[Incomplete, Incomplete, TimeType]: ... def AcceptSecurityContext( Credential: _win32typing.PyCredHandle, Context: _win32typing.PyCtxtHandle,