Search code examples
pythonpywin32

Can't find module, which contains PyHANDLE for type annotation


I wanted to find a type of value, returning by win32file.CreateFile() in python. From post i learned that it must be a pywintypes.HANDLE object.

But i sill got "cannot find reference" warning when i try to annotate my handle object like that:

import pywintypes
import win32file

handle: pywintypes.HANDLE

handle = win32file.CreateFile(args)

So, how to annotate this variable correctly?


Solution

  • In the post which you mentioned, was this example:

    hwnd = win32gui.FindWindow(None, "window")  # Return handle as an integer
    
    PyHANDLE = pywintypes.HANDLE(hwnd)
    

    In your case, you just annotated variable. I don't know what you want to do, but if you want to use pywintypes like in the post, you may to try this:

    import pywintypes
    import win32file
    
    
    win32_created_file = win32file.CreateFile(args)
    handle: pywintypes.HANDLE = pywintypes.HANDLE(win32_created_file)