Skip to content

Add deprecation decorator and comments for pywin32#11570

Merged
JelleZijlstra merged 11 commits intopython:mainfrom
Avasam:pywin32-deprecation-messages
Mar 11, 2024
Merged

Add deprecation decorator and comments for pywin32#11570
JelleZijlstra merged 11 commits intopython:mainfrom
Avasam:pywin32-deprecation-messages

Conversation

@Avasam
Copy link
Copy Markdown
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.

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
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

NCBType = _win32typing.PyNCB
NETRESOURCE = _win32typing.PyNETRESOURCE
NCB = _win32typing.PyNCB
# old "deprecated" names, before types could create instances.
Copy link
Copy Markdown
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. 🤷

@github-actions

This comment has been minimized.

Comment thread stubs/pywin32/_win32typing.pyi
Comment thread stubs/pywin32/_win32typing.pyi Outdated
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
Copy Markdown
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")

Comment thread stubs/pywin32/_win32typing.pyi Outdated
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
Copy Markdown
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")

Comment thread stubs/pywin32/_win32typing.pyi Outdated
@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
Copy Markdown
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")

Comment thread stubs/pywin32/_win32typing.pyi Outdated
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
Copy Markdown
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")

Comment thread stubs/pywin32/_win32typing.pyi Outdated
@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
Copy Markdown
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
Copy Markdown
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.

Comment thread stubs/pywin32/pythoncom.pyi Outdated
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
Copy Markdown
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

Comment thread stubs/pywin32/pythoncom.pyi Outdated
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
Copy Markdown
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.")

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
Copy Markdown
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."

class DispatcherOutputDebugString(DispatcherTrace): ...

class DispatcherWin32dbg(DispatcherBase):
@deprecated(
Copy link
Copy Markdown
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
Copy Markdown
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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread stubs/pywin32/_win32typing.pyi Outdated
@github-actions

This comment has been minimized.

Comment thread stubs/pywin32/_win32typing.pyi Outdated
Comment thread stubs/pywin32/win32/lib/win32pdhquery.pyi Outdated
Avasam and others added 2 commits March 11, 2024 11:12
@github-actions
Copy link
Copy Markdown
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