Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ def MakePublicAttributeName(className, is_global=False):
if ret == className: # didn't change - force all uppercase.
ret = ret.upper()
return ret
elif className.isidentifier():
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this is just trying to be isidentifier() - so maybe also kill the whole valid_identifier_chars thing?

Copy link
Copy Markdown
Contributor Author

@native-api-work native-api-work Jun 26, 2025

Choose a reason for hiding this comment

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

isidentifier() doesn't allow names that are partially valid. I don't know how likely such names are.

https://learn.microsoft.com/en-us/windows/win32/api/oaidl/nf-oaidl-idispatch-gettypeinfo#parameters explicitly mentions that "localized member names" are allowed -- but doesn't list any constraints.
Since IDispatch only ever deals with member names as strings, it seems that theoretically, any string whatsoever is valid.

If that is the case, an ideal solution would be to filter out any characters that are invalid according to Python identifier rules -- but CPython doesn't provide any facilities to check if a character has XID_Start or XID_Continue Unicode property other than via isidentifier(). So the proposed change is a stopgap solution.
There are 3rd-party modules that can check Unicode properties, e.g. https://pypi.org/project/regex/ , if that's an option.

# some COM objects have identifiers with national characters
return className
# Strip non printable chars
return "".join([char for char in className if char in valid_identifier_chars])

Expand Down