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

Stubs do not recognize classes as importable modules #17

Open
maxsu opened this issue Oct 2, 2023 · 0 comments
Open

Stubs do not recognize classes as importable modules #17

maxsu opened this issue Oct 2, 2023 · 0 comments

Comments

@maxsu
Copy link

maxsu commented Oct 2, 2023

First I want to express my thanks for pythonstubs. It it has the potential to help our org better maintain our legacy rhinopython code. Second, I would like to express a problem we're having, and propose a solution.

In our rhino python code, we like to explicitly import static functions from Rhino classes when possible, to help telegraph the intention of an import:

from Rhino.Geometry.Rtree import CreatePointCloudTree #  I bet we'll create a point cloud tree later 🤔
{...}
CreatePointCloudTree(some_points) #  How did we know that?! 🤯

However, the current stub setup will fail to recognize these sorts of imports (for example in pycharm):

image

The crux is that RhinoPython lets us import a .net class as if it were a python module. However, the current stub layout - one .pyi per major rhino namespace - can't recognize these "class module" style imports.

To resolve the issue in the most literal way, we could represent the additional class modules as .pyi stubs. These stubs would correctly recognize the import examples I've shown:

# Import                                     #  Stub
import Rhino.Geometry.Sphere   #  /Rhino-stubs/Geometry/Sphere.pyi
import Rhino.Geometry.RTree      #  /Rhino-stubs/Geometry/RTree.pyi
etc.

Pystubbler would dump these "class modules" using the same method it uses to dump namespace modules. This would make the stubs significantly more faithful to the true article, and more fit to our organization's needs.

Feedback would be welcome. This capability would be useful for our organization; if a particular solution design gets maintainer endorsement, I would like to sponsor and submit the fix.

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

No branches or pull requests

1 participant