Skip to content

Stop using (exposing) deprecated Py_FrozenFlag #2593

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Apr 30, 2025

This PR aims to stop using Py_FrozenFlag, solving one of the C API deprecation in #2588

The initial version of this PR does so by deprecating pythoncom.frozen in favor of getattr(sys, "frozen", False).
This is mainly motivated by the side-effect hack importing win32com does on pythoncom.frozen.

An alternative is to give more utility to pythoncom.frozen by officially making it a wrapper to getattr(sys, "frozen", False) allowing users to simply use pythoncom.frozen instead of messing with getattr themselves. But I think it's fair to ask if it's pywin32's job to offer a helper property-like attribute to an optional sys attribute unrelated to Windows ? (if pywin32 uses its own helper though, that's fine).

@Avasam Avasam force-pushed the Stop-using-Py_FrozenFlag branch from 55b81a3 to 733d865 Compare April 30, 2025 17:01
@@ -302,7 +301,7 @@ def RegisterServer(
_remove_key(keyNameRoot + "\\PythonCOMPath")

if addPyComCat is None:
addPyComCat = pythoncom.frozen == 0
addPyComCat = __frozen == False
Copy link
Collaborator Author

@Avasam Avasam Apr 30, 2025

Choose a reason for hiding this comment

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

I would've done

Suggested change
addPyComCat = __frozen == False
addPyComCat = not __frozen

But since pythoncom.frozen = sys.frozen, and we see above that sys.frozen could be "dll". "dll" != 0.

I don't know if this was an oversight or intended behaviour, so I kept the current behaviour.

@Avasam Avasam force-pushed the Stop-using-Py_FrozenFlag branch 2 times, most recently from f5f985d to eaea420 Compare April 30, 2025 21:02
Comment on lines +9 to +13
# This module dynamically re-exports from a C-Extension.
# `__getattr__() -> Any` prevents checkers attribute access errors
# without the use of external type stubs.
# So keep it even if pythoncom.frozen support is removed.
def __getattr__(name: str) -> Any:
Copy link
Collaborator Author

@Avasam Avasam Apr 30, 2025

Choose a reason for hiding this comment

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

This incidentally has the exact same benefits as https://github.com/mhammond/pywin32/pull/2418/files#diff-417d6662c94f9f97ab29ec3611822c62e6da513054d38f6dfdc0155fc2f4463b
(which does:

from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
    def __getattr__(name: str) -> Any: ...

)

@Avasam Avasam force-pushed the Stop-using-Py_FrozenFlag branch from eaea420 to c3b7b17 Compare April 30, 2025 21:06
@Avasam Avasam requested a review from mhammond April 30, 2025 21:50
@Avasam Avasam force-pushed the Stop-using-Py_FrozenFlag branch from c3b7b17 to 4e6f444 Compare April 30, 2025 23:07
@Avasam Avasam mentioned this pull request May 2, 2025
7 tasks
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.

1 participant