Skip to content

Add deprecation decorator and comments for pywin32 #11570

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

Merged
merged 11 commits into from
Mar 11, 2024

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Mar 11, 2024

I searched and read the source for deprecat and obsolet
Fixed the type of some methods I touched here. All typing changes are tested.

@@ -233,6 +237,11 @@ def SetSystemPowerState(Suspend, Force, /) -> None: ...
def SetThreadLocale(lcid, /) -> None: ...
def SetTimeZoneInformation(tzi, /): ...
def SetWindowLong(hwnd: int | None, offset: int, value: float, /) -> int: ...

# This method is accidentally overwritten in source, can re-introduce once fixed:
# https://github.com/mhammond/pywin32/pull/2199
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NETRESOURCE = _win32typing.PyNETRESOURCE
NCB = _win32typing.PyNCB
# old "deprecated" names, before types could create instances.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What's weird is that it seems to be the other way around everywhere else. Where ClassType is the reference type, and Class is a method that creates an instance of PyClass.
The exception to the rule I guess. 🤷

This comment has been minimized.

@@ -3682,7 +3706,11 @@ class PyIInternetPriority:

class PyIInternetProtocol:
def Read(self, cb, /) -> None: ...
def Seek(self, dlibMove: LARGE_INTEGER, dwOrigin, /) -> None: ...
@overload
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
@deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead")

def ReadAt(self, ulOffset: ULARGE_INTEGER, cb, /) -> str: ...
def WriteAt(self, ulOffset: ULARGE_INTEGER, data: str, /): ...
@overload
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
@deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead")

@overload
def ReadAt(self, ulOffset: int, cb, /) -> str: ...
@overload
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
@deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead")

def UnlockRegion(self, libOffset: ULARGE_INTEGER, cb: ULARGE_INTEGER, dwLockType, /) -> None: ...
def Stat(self, grfStatFlag, /) -> STATSTG: ...
@overload
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
@deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead")

@overload
def LockRegion(self, libOffset: int, cb: int, dwLockType, /) -> None: ...
@overload
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("Support for passing 2 integers to create a 64bit value is deprecated - pass an int instead")
@deprecated("Support for passing two ints to create a 64-bit value is deprecated; pass a single int instead")

Seems like this occurs a bunch more times, please change the remaining ones too

Copy link
Collaborator Author

@Avasam Avasam Mar 11, 2024

Choose a reason for hiding this comment

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

Yeah I copied the string from source (almost) verbatim. Except I replaced long for int, so I don't mind changing it slightly further.

@@ -69,6 +69,10 @@ def IsGatewayRegistered(iid: _win32typing.PyIID | None, /) -> int: ...
def LoadRegTypeLib(iid: _win32typing.PyIID, versionMajor, versionMinor, lcid, /) -> _win32typing.PyITypeLib: ...
def LoadTypeLib(libFileName: str, /) -> _win32typing.PyITypeLib: ...
def MakePyFactory(iid: _win32typing.PyIID, /) -> _win32typing.PyIClassFactory: ...
@deprecated("MakeIID is deprecated - please use pywintypes.IID() instead.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("MakeIID is deprecated - please use pywintypes.IID() instead.")
@deprecated("Use pywintypes.IID() instead.")

Type checker messages should already point out the name of the function

@@ -69,6 +69,10 @@ def IsGatewayRegistered(iid: _win32typing.PyIID | None, /) -> int: ...
def LoadRegTypeLib(iid: _win32typing.PyIID, versionMajor, versionMinor, lcid, /) -> _win32typing.PyITypeLib: ...
def LoadTypeLib(libFileName: str, /) -> _win32typing.PyITypeLib: ...
def MakePyFactory(iid: _win32typing.PyIID, /) -> _win32typing.PyIClassFactory: ...
@deprecated("MakeIID is deprecated - please use pywintypes.IID() instead.")
def MakeIID(iidString: str, is_bytes: bool = ..., /) -> _win32typing.PyIID: ...
@deprecated("MakeTime is deprecated - please use pywintypes.Time() instead.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@deprecated("MakeTime is deprecated - please use pywintypes.Time() instead.")
@deprecated("Use pywintypes.Time() instead.")

@@ -24,6 +25,10 @@ class BaseQuery:
class Query(BaseQuery):
volatilecounters: Incomplete
def __init__(self, *args, **namedargs) -> None: ...
@deprecated(
"The use of addperfcounter by end-users is deprecated, since the use of addcounterbybrowsing is considerably more flexible and general."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The use of addperfcounter by end-users is deprecated, since the use of addcounterbybrowsing is considerably more flexible and general."
"Use addcounterbybrowsing instead."

@@ -17,6 +17,12 @@ class DispatcherWin32trace(DispatcherTrace):
class DispatcherOutputDebugString(DispatcherTrace): ...

class DispatcherWin32dbg(DispatcherBase):
@deprecated(
Copy link
Member

Choose a reason for hiding this comment

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

Should this be on the class instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah you can do that! Any usage of the class (even as type hint) appears as deprecated in Pylance. Sure.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 579d208 into python:main Mar 11, 2024
@Avasam Avasam deleted the pywin32-deprecation-messages branch March 11, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants