-
Notifications
You must be signed in to change notification settings - Fork 841
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
Avasam
wants to merge
4
commits into
mhammond:main
Choose a base branch
from
Avasam:Stop-using-Py_FrozenFlag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−31
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4e6f444
Stop using Py_FrozenFlag
Avasam cbb96d8
Merge branch 'main' into Stop-using-Py_FrozenFlag
Avasam 820a65b
Post-merge don't add back BOM
Avasam 86e178c
Merge branch 'main' of https://github.com/mhammond/pywin32 into Stop-…
Avasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
# Magic utility that "redirects" to pythoncomXX.dll | ||
from typing import Any | ||
|
||
import pywintypes | ||
|
||
pywintypes.__import_pywin32_system_module__("pythoncom", globals()) | ||
|
||
|
||
# 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: | ||
if name == "frozen": | ||
import sys | ||
import warnings | ||
|
||
warnings.warn( | ||
f"`pythoncom.frozen` used to expose `Py_FrozenFlag` from the C API. " | ||
+ "`Py_FrozenFlag` is deprecated since Python 3.12. " | ||
+ "Ever since pywin32 b200, loading the `win32com` module has silently " | ||
+ "been replacing `pythoncom.frozen` with `sys.frozen`. " | ||
+ 'Use `getattr(sys, "frozen", False)` directly instead.', | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return getattr(sys, "frozen", False) | ||
else: | ||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,8 @@ | |||||
|
||||||
""" | ||||||
|
||||||
from __future__ import annotations | ||||||
|
||||||
import os | ||||||
import sys | ||||||
|
||||||
|
@@ -17,6 +19,8 @@ | |||||
|
||||||
CATID_PythonCOMServer = "{B3EF80D0-68E2-11D0-A689-00C04FD658FF}" | ||||||
|
||||||
__frozen: str | bool = getattr(sys, "frozen", False) | ||||||
|
||||||
|
||||||
def _set_subkeys(keyName, valueDict, base=win32con.HKEY_CLASSES_ROOT): | ||||||
hkey = win32api.RegCreateKey(base, keyName) | ||||||
|
@@ -207,13 +211,9 @@ def RegisterServer( | |||||
# Set default clsctx. | ||||||
if not clsctx: | ||||||
clsctx = pythoncom.CLSCTX_INPROC_SERVER | pythoncom.CLSCTX_LOCAL_SERVER | ||||||
# And if we are frozen, ignore the ones that don't make sense in this | ||||||
# context. | ||||||
if pythoncom.frozen: | ||||||
assert sys.frozen, ( | ||||||
"pythoncom is frozen, but sys.frozen is not set - don't know the context!" | ||||||
) | ||||||
if sys.frozen == "dll": | ||||||
# And if we are frozen, ignore the ones that don't make sense in this context. | ||||||
if __frozen: | ||||||
if __frozen == "dll": | ||||||
clsctx &= pythoncom.CLSCTX_INPROC_SERVER | ||||||
else: | ||||||
clsctx &= pythoncom.CLSCTX_LOCAL_SERVER | ||||||
|
@@ -223,7 +223,7 @@ def RegisterServer( | |||||
# nod to Gordon's installer - if sys.frozen and sys.frozendllhandle | ||||||
# exist, then we are being registered via a DLL - use this DLL as the | ||||||
# file name. | ||||||
if pythoncom.frozen: | ||||||
if __frozen: | ||||||
if hasattr(sys, "frozendllhandle"): | ||||||
dllName = win32api.GetModuleFileName(sys.frozendllhandle) | ||||||
else: | ||||||
|
@@ -261,9 +261,8 @@ def RegisterServer( | |||||
_remove_key(keyNameRoot + "\\InprocServer32") | ||||||
|
||||||
if clsctx & pythoncom.CLSCTX_LOCAL_SERVER: | ||||||
if pythoncom.frozen: | ||||||
# If we are frozen, we write "{exe} /Automate", just | ||||||
# like "normal" .EXEs do | ||||||
if __frozen: | ||||||
# If we are frozen, we write "{exe} /Automate", just like "normal" .EXEs do | ||||||
exeName = win32api.GetShortPathName(sys.executable) | ||||||
command = f"{exeName} /Automate" | ||||||
else: | ||||||
|
@@ -302,7 +301,7 @@ def RegisterServer( | |||||
_remove_key(keyNameRoot + "\\PythonCOMPath") | ||||||
|
||||||
if addPyComCat is None: | ||||||
addPyComCat = pythoncom.frozen == 0 | ||||||
addPyComCat = __frozen == False | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would've done
Suggested change
But since I don't know if this was an oversight or intended behaviour, so I kept the current behaviour. |
||||||
if addPyComCat: | ||||||
catids = catids + [CATID_PythonCOMServer] | ||||||
|
||||||
|
@@ -422,7 +421,7 @@ def RegisterClasses(*classes, **flags): | |||||
clsctx = _get(cls, "_reg_clsctx_") | ||||||
tlb_filename = _get(cls, "_reg_typelib_filename_") | ||||||
# default to being a COM category only when not frozen. | ||||||
addPyComCat = not _get(cls, "_reg_disable_pycomcat_", pythoncom.frozen != 0) | ||||||
addPyComCat = not _get(cls, "_reg_disable_pycomcat_", __frozen) | ||||||
addnPath = None | ||||||
if debugging: | ||||||
# If the class has a debugging dispatcher specified, use it, otherwise | ||||||
|
@@ -455,7 +454,7 @@ def RegisterClasses(*classes, **flags): | |||||
|
||||||
spec = moduleName + "." + cls.__name__ | ||||||
# Frozen apps don't need their directory on sys.path | ||||||
if not pythoncom.frozen: | ||||||
if not __frozen: | ||||||
scriptDir = os.path.split(sys.argv[0])[0] | ||||||
if not scriptDir: | ||||||
scriptDir = "." | ||||||
|
@@ -664,7 +663,7 @@ def RegisterPyComCategory(): | |||||
regCat.RegisterCategories([(CATID_PythonCOMServer, 0x0409, "Python COM Server")]) | ||||||
|
||||||
|
||||||
if not pythoncom.frozen: | ||||||
if not __frozen: | ||||||
try: | ||||||
win32api.RegQueryValue( | ||||||
win32con.HKEY_CLASSES_ROOT, | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
)