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

Open3D type checking bug/issue #3052

Open
BojanMatovski opened this issue Feb 17, 2021 · 6 comments · May be fixed by #6917
Open

Open3D type checking bug/issue #3052

BojanMatovski opened this issue Feb 17, 2021 · 6 comments · May be fixed by #6917

Comments

@BojanMatovski
Copy link

BojanMatovski commented Feb 17, 2021

Describe the bug
Since the Open3D update I get this kind of a warning (see screenshots) in PyCharm when I try to add a point cloud as a geometry in a visualizer.

I've also seen issues like "Expected type 'PointCloud.py', got 'PointCloud' instead", where the only difference is that the expected type is the type of the object I am already giving but followed by a ".py"

To Reproduce

  1. Start PyCharm
  2. Write a test program that uses the geometry, or pointcloud objects (even some others)
  3. Create an object of some of those types, but explicitly define the type, i.e.:
    some_pointcloud: open3d.geometry.PointCloud = open3d.geometry.PointCloud() (added another screenshot for this example)
  4. Give it as an input to the method that uses such object

Expected behavior
The method should accept the input object and PyCharm shouldn't complain about it.

Screenshots
image
image

Environment (please complete the following information):

  • Operating system: Windows 10 64-bit
  • Python version: Python 3.8 (but it happens in other Python versions I believe)
  • Open3D version: Open3D 12 (but I think it also happened in 11, not 100% sure though)
  • Is this remote workstation?: no
  • How did you install Open3D?: pip (through PyCharm)
  • Compiler version (if built from source): n/a

Additional context
I opened this discussion on Discord, but there were no responses, so I assume that it is a bug. Also, in the geometry issue, I've tried casting it to a geometry object type, but there were some issues with the geometry object constructor. I searched the documentation to try and see if I'm doing something wrong, but I couldn't find anything specific to this.

By the way, nothing crashes, everything works as intended, it's just these silly warnings that the static code analyzer complains about.

@ssheorey
Copy link
Member

ssheorey commented Mar 5, 2021

Hi @BojanMatovski which static analyser does PyCharm use? Can you reproduce this with pylint or flake8?

@BojanMatovski
Copy link
Author

I am not sure which static analyzer PyCharm uses. I tried looking out and finding it, but couldn't really do it.

I tried using flake8, but had some issues with it. When I try using it, it prints:
AttributeError: 'TreeRebuilder3' object has no attribute 'visit_constant'

I also tried catching it with pylint and it doesn't catch it, but I might need to configure it or something, because I also added these two lines as a check:

        a: int = 'test'
        print(a)

and pylint still doesn't complain about the variable "being" an integer and having a string assigned.

Finally, I tried mypy, but for some reason it says that open3d has no type hinting:
error: Skipping analyzing 'open3d': found module but no type hints or library stubs

@theNded theNded added the misc label Nov 21, 2021
@ssheorey
Copy link
Member

ssheorey commented Dec 3, 2021

@BojanMatovski Open3D doesn't use type hints, since the code is a compiled C++ module. I don't believe type hints are useful here since C++ already has strong type safety.
Looks like PyCharm is not able to analyze compiled modules, I would just configure it to skip checking Open3D code if possible.
Closing this issue. Please re-open if you have suggestions on improving compatibility with these tools.

@ssheorey ssheorey closed this as completed Dec 3, 2021
@ManuCorrea
Copy link

Hello @ssheorey!

I am trying to apply type checking to my project in order to have a robust CI. I type my functions which usually have Open3D objects.

Using mypy I get the following error:
error: Skipping analyzing "open3d": module is installed, but missing library stubs or py.typed marker [import-untyped]

In order to improve the compatibility with these kind of tools Open3D should be PEP 561, the following links give a starting point:
https://mypy.readthedocs.io/en/stable/installed_packages.html#installed-packages
https://peps.python.org/pep-0561/#type-checker-module-resolution-order

@ssheorey
Copy link
Member

Hi @ManuCorrea here are two options for generating stubs:

https://github.com/sizmailov/pybind11-stubgen
https://mypy.readthedocs.io/en/stable/stubgen.html#automatic-stub-generation-stubgen

with a discussion here:
pybind/pybind11#2350

If any of these tools work for you, please let us know. Also happy to accept a PR to package these stubs in the Open3D wheel based on your results.

@ssheorey ssheorey reopened this Nov 14, 2023
@ssheorey ssheorey removed the misc label Apr 28, 2024
@martincerven
Copy link

@ssheorey OpenCV also added type hints with .pyi files opencv/opencv#14590

The stub generation with https://github.com/sizmailov/pybind11-stubgen works, although in vscode you have to copy generated file in root of your workspace or some pylance folder #5802

Is the reason why Open3D doesn't have type hints that the functions are generated with pybind11?
Would it be possible to generate .pyi files https://github.com/sizmailov/pybind11-stubgen and ship them with the library?

@timohl timohl linked a pull request Aug 14, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants