A minor annoyance with the Pycharm setup for depthai that I can't resolve.
In short - Using any example piece of code from any of the depthai repos (depthai-python/examples, experiments, etc) I find that Pycharm can't resolve any reference to any function that returns an object of type ADatatype.

Has anyone faced this? The code always runs fine in all cases, but the Pycharm indexer can't seem to resolve the reference. As far as I ca see, all other references/types/variables/functions etc resolve just fine out of the box and show the associated docs, it seems to be limited to ADatatype objects

Here's a simple example showing just a snippet of the edge_detector.py

    while(True):
        edgeLeft = edgeLeftQueue.get()
        edgeRight = edgeRightQueue.get()
        edgeRgb = edgeRgbQueue.get()

        edgeLeftFrame = edgeLeft.getFrame()
        edgeRightFrame = edgeRight.getFrame()
        edgeRgbFrame = edgeRgb.getFrame()

On hover, I get the popup Unresolved attribute reference 'getFrame' for class 'ADatatype'
Is there any way to force the indexer to include the ADatatype object reference, or is it an intrinsic limitation of using this type of object?

Happy to provide more info if required, just trying to keep the clutter to minimum.

Thanks.

  • erik replied to this.

    Hello mikegardner ,
    Which depthai version are you using? I believe that newer ones have this support, at least in VS code.
    Thanks, Erik

    Hi Erik, I think I'm using the very latest version, I re-installed a couple of days ago to see if it made a difference, using the instructions from the site. https://docs.luxonis.com/projects/api/en/latest/install/
    The version showing in the PyCharm 'Python Packages' list box is depthai 2.15.2.0

    I'll try the above edge_detector.py example on VS Code and see how that behaves, and report back. Thanks.

    I tried the same file with VS Code straight out of the box and it's different. Here are a few of the entries in the VS Code problem log.

    "message": "\"node\" is not a known member of module",
    "message": "Cannot access member \"setStreamName\" for type \"AprilTag\"
    "message": "Cannot access member \"setBoardSocket\" for type \"AprilTag\"
    "message": "Cannot access member \"setResolution\" for type \"AprilTag\"
    "message": "Cannot access member \"setMaxOutputFrameSize\" for type \"AprilTag\"
    "message": "Cannot access member \"getVideoWidth\" for type \"AprilTag\"
    "message": "Cannot access member \"getVideoHeight\" for type \"AprilTag\"

    There are a quite a few more entries in practice which suggests to me that VS Code requires some manual configuration to get the indexer set up properly. So the VS Code aspect may be a distraction, as it works in my depthai environment for C++ .

    I would like to get PyCharm setup correctly as it is recommended as the IDE of choice in the installation section...

    https://docs.luxonis.com/projects/api/en/latest/install/?highlight=pycharm#test-installation

    For development machines like Mac/Windows/Ubuntu/etc., we recommend the PyCharm IDE, as it automatically makes/manages virtual environments for you, along with a bunch of other benefits.

    As I say it's a minor annoyance rather than a real issue, as all of the code works. It's just bothers me that something's not quite right with the indexing, and I'd like to understand it in order to fix it.

    Any thoughts appreciated.

    @mikegardner

    The file that is used to provide this can be found by doing python -m pip show depthai and using the Location to see the filed under directory [Location]/depthai/__init__.pyi and node.pyi

    Regarding getFrame that could be fixed by specifying that DataOutputQueue.get could return ADatatype OR any of its descendants (As of right now, the typed information doesn't point to that, so IDEs cannot know that it might return subclasses as well). That could be done using overloads, similarly to Pipeline.create.

    If you'd like to check it out how these are done, see depthai-python/generate_stubs.py. It uses stubgen and mypy to check if stubs can be parsed correctly.

    Any improvements are welcome🙂

    Regarding VSCode, it AFAIK uses a different typing system underneath and it might have more issues without any additional configuration. I've only tested it briefly there.

    Best regards,
    Martin