-
Notifications
You must be signed in to change notification settings - Fork 793
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
Replace strings by actual Exception subclasses #2270
Conversation
com/win32com/server/policy.py
Outdated
@@ -210,7 +205,7 @@ def _CreateInstance_(self, clsid, reqIID): | |||
win32con.HKEY_CLASSES_ROOT, regSpec % clsid | |||
) | |||
except win32api.error: | |||
raise error( | |||
raise COMException( |
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.
I don't even know if these even make sense as COMExceptions, this is not an area I'm familiar with at all. Please advise which exception you'd like to raise.
Maybe just a re-raise with a different message?
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.
I think a COM exception is not quite correct - maybe ValueError
, because ultimately this is complaining that the value of clsid
is invalid in this context/on this machine?
I think that's true for all other exceptions in this file - could maybe argue TypeError
for some of them, but I don't think it matters in practice - the errors below here are never expected to be hit "for real", but only while the COM object is being developed.
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.
Went with ValueError
for most, and NotImplementedError
for _invokeex_
as the message, comment and docstring all seem to point to this fitting the semantics of https://docs.python.org/3/library/exceptions.html#NotImplementedError
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.
The rest looks great though, thanks!
com/win32com/server/policy.py
Outdated
@@ -210,7 +205,7 @@ def _CreateInstance_(self, clsid, reqIID): | |||
win32con.HKEY_CLASSES_ROOT, regSpec % clsid | |||
) | |||
except win32api.error: | |||
raise error( | |||
raise COMException( |
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.
I think a COM exception is not quite correct - maybe ValueError
, because ultimately this is complaining that the value of clsid
is invalid in this context/on this machine?
I think that's true for all other exceptions in this file - could maybe argue TypeError
for some of them, but I don't think it matters in practice - the errors below here are never expected to be hit "for real", but only while the COM object is being developed.
…ng-string-as-errors
Fixes #1902
There's a few attempted approaches on a case-by-case scenario. You'll need to open the full files to find where
raise error(
is called.As a general question, should we try to replace them all with direct exception calls? (
RuntimeError
,TypeError
,ValueError
,pywintypes.error
,COMException
, ...), or should new module-specific exceptions be created?Same question as in #2269 : Should they still be accessible with a deprecation warning ? Or is it ok to remove them?
(no changelog entry yet as the decision for a solution isn't final)