-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Iterators in generated files implementing next()
instead of __next__()
#353
Comments
Perhaps the related code is around there. comtypes/comtypes/tools/codegenerator.py Lines 809 to 859 in fed3de6
A com object which has Lines 410 to 433 in fed3de6
But a com object with no
I think this issue can be resolved by only changing |
@psisquared2 Please let me know your code that you expected to work correctly (and terminated abnormally). I may be able to get some hints from that code as to what test cases would guarantee the behavior. |
@psisquared2 I am planning to add a type-stub generating process to the So you are free from the worry of code conflictions with your |
@psisquared2 Can you remind this? The
And can you react to below?
|
My apologies, I had a few busy months and found no time to focus on my project involving
Both sounds very good. I suspect that one can just rename
I put together this rough sketch based on https://github.com/KasparNagu/PortableDevices: import ctypes
import comtypes
import comtypes.client
comtypes.client.GetModule("portabledeviceapi.dll")
comtypes.client.GetModule("portabledevicetypes.dll")
import comtypes.gen._1F001332_1A57_4934_BE31_AFFC99F4EE0A_0_1_0 as port
import comtypes.gen._2B00BA2F_E750_4BEB_9235_97142EDE1D3E_0_1_0 as types
clientInformation = comtypes.client.CreateObject(
types.PortableDeviceValues,
clsctx=comtypes.CLSCTX_INPROC_SERVER,
interface=port.IPortableDeviceValues)
_device = comtypes.client.CreateObject(
port.PortableDevice,
clsctx=comtypes.CLSCTX_INPROC_SERVER,
interface=port.IPortableDevice)
_device.Open('<valid device id like "\\\\?\\usb#vid_18d1&pid_4...{<GUID>}">', clientInformation)
objects = _device.Content().EnumObjects(ctypes.c_ulong(0), "DEVICE", None)
for obj in objects:
print(obj) This only works if I change |
Thank you for your response. I have created the TestCase from the sample code you provided. comtypes/comtypes/test/test_portabledevice.py Lines 1 to 60 in 6d136d1
Check the test content. It does not CREATE, DELETE or UPDATE and may not damage your portable device. Please create a new branch in your local repo from the
comtypes/comtypes/tools/codegenerator.py Lines 998 to 1048 in 6d136d1
comtypes/comtypes/tools/codegenerator.py Line 1032 in 6d136d1
↓ print(" def __next__(self):", file=self.stream)
Also, if you know, please let me know safe way to do this, like having a virtual portable device and using the COM API for it. |
I did the test as you described and I can confirm the correct behaviour:
Unfortunately I don't have the backgrounds in the WPD API to give advice on how to unit-test the code without a device connected. As far as I am concerned this issue can be closed, but maybe you want to keep it open until |
As you may have guessed, I will keep this issue open at least until a commit is added that makes changes to the production codebase. Are you interested in contributing to this project? |
Thanks, I appreciate the opportunity - too often have I seen collaborators just fixing issues without acknowledgement even in cases where the contribution was significantly larger than mine here. |
I am interested in a healthy expansion of the OSS community. Such as this case, the ideal is for those who find a problem to solve it with the help of the community and submit a PR for the fix. I believe that there are more eyes👀, mouths👄, ears👂, and wisdom🧠, in other words, keeping developer community active👯👥 makes it easier to identify and solve problems that depends on the user’s/developer’s environment. |
The commit that fixed this issue has been merged into the |
The following code was generated on comtypes 1.1.14 using
comtypes.client.GetModule("portabledeviceapi.dll")
:While trying to do some basic type annotation I realised that a
__next__()
method is missing, hence the return value of__iter__()
is not an iterator. The best fix which won't break existing code is likely to just automatically addto every class generated in such a way.
The text was updated successfully, but these errors were encountered: