Skip to content
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

adjust import style and references in client.dynamic #438

Closed
junkmd opened this issue Dec 31, 2022 · 1 comment · Fixed by #439
Closed

adjust import style and references in client.dynamic #438

junkmd opened this issue Dec 31, 2022 · 1 comment · Fixed by #439
Assignees
Labels
drop_py2 dev based on supporting only Python3, see #392 good first issue Good for newcomers

Comments

@junkmd
Copy link
Collaborator

junkmd commented Dec 31, 2022

THIS IS FOR drop_py2 PLAN! Please see #392.

Some import styles and references to module.object are redundant.
In addition, there are some points that are not a problem at runtime but raise errors or warnings in static analysis.

  • For example, comtypes.COMError on line 30.
    When importing comtypes.automation, its "parent" comtypes are also loaded, so there is no problem at runtime, but since comtypes itself is not imported, static analysis raises an error.

import ctypes
import comtypes.automation
import comtypes.typeinfo
import comtypes.client
import comtypes.client.lazybind
from comtypes import COMError, IUnknown, _is_object
import comtypes.hresult as hres

def Dispatch(obj):
# Wrap an object in a Dispatch instance, exposing methods and properties
# via fully dynamic dispatch
if isinstance(obj, _Dispatch):
return obj
if isinstance(obj, ctypes.POINTER(comtypes.automation.IDispatch)):
try:
tinfo = obj.GetTypeInfo(0)
except (comtypes.COMError, WindowsError):
return _Dispatch(obj)
return comtypes.client.lazybind.Dispatch(obj, tinfo)
return obj

image

Modernize the codebase by removing static analysis errors and import redundancies.

@junkmd junkmd added good first issue Good for newcomers drop_py2 dev based on supporting only Python3, see #392 labels Dec 31, 2022
@junkmd junkmd self-assigned this Dec 31, 2022
@junkmd
Copy link
Collaborator Author

junkmd commented Dec 31, 2022

I created this issue to serve as a "model case" for future good first issue that I will submit.

I will work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drop_py2 dev based on supporting only Python3, see #392 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant