Python typing - Iterable

Hello,

It is possible to complete Rhino3dm’s PYI, more exactly all iterable objects break type annotations.
Such as File3dmObjectTable or Iterable[...]
jmv

In fact, a lot of information is missing.

There must be an error or a lack in the stubs generator because no class is extended by the base class. The example of “PolylineCurve”

    class PolylineCurve:
        @property
        def PointCount(self) -> int: ...
        def Point(self, index: int) -> Point3d: ...
        def SetPoint(self, index: int, point: Point3d) -> None: ...
        def ToPolyline(self) -> Polyline: ...

But it is a subclass of “Curve”

    class PolylineCurve(Curve):
        ...

So if you don’t know the API things like:

    PolylineCurve.IsClosed

are unknown to rhino3dm beginners and the linter.
All classes are like this. It would be nice for little guys like me to add the base class.

In addition, some of the more common structures are incomplete.
This is the case for example of the “Line” structure:

    class Line:
        def __init__(self, _from: Point3d, to: Point3d): ...
        @property
        def IsValid(self) -> bool: ...
        @property
        def Length(self) -> float: ...
        @property
        def Direction(self) -> Vector3d: ...
        @property
        def UnitTangent(self) -> Vector3d: ...
        def PointAt(self, t: float) -> Point3d: ...

There, if you don’t know, you might think that the starting or ending point is not available. However, the “From” and “To” properties exists.

Same for “Point3d” which does not contain “X”, “Y” and “Z”.

It seems that the structures do not contain the properties of the instances.

I wish I could do things with Python and Rhino, I’m not talking about becoming an expert but being able to write a few useful lines.
I am not criticizing, but there is too much lack for your work to be useful.
Currently the stubs are only on surface. I hope you will find the time.

Thanks, I created an issue for this at

Thank you. It would help me a lot.
I’m not really a programmer if the IDE doesn’t guide me and the Linter doesn’t think for me …)

Oh!!! But you have already fixed it !!
:+1: :+1: :+1:

I haven’t published new builds of rhino3dm to pypi yet. I’m working on this now.

1 Like

I don’t know if you’ve seen this but inside VScode (pylance) something like:

class ArcCurve(Curve):
    @property
    def Arc(self) -> Arc: ...

does not find the reference to class Arc but at its property ArcCurve.Arc

I did not find any other solution than to write:

from typing_extensions import TypeAlias
_Arc: TypeAlias = Arc
class ArcCurve(Curve):
    @property
    def Arc(self) -> _Arc: ...

https://docs.python.org/fr/3.10/library/typing.html#special-typing-primitives

I see this too. I’ve had some issues with pylance since it was released, but I’m not really sure if that is to blame. Even properties that return basic types like float are not recognized.

For example, why is pylance getting confused over basic types as shown here?

Oh, on my side everything is good for me and correctly find stdlib/buitins.pyi

my user settings


    "python.jediEnabled": false,
    "python.languageServer": "Pylance",
    "python.defaultInterpreterPath": "C:\\Program Files\\Python37\\python.exe",
    "python.analysis.extraPaths": [
        ...,
        "E:\\Application\\3d\\Mod\\Blender\\Plugin\\IO\\io_import_3dm\\import_3dm-v0.0.8.win"
    ],

I had an old path to typeshed files and it looks like this was messed up when VS Code updated to use pylance. I removed the path entry and am now getting better results. I still see the problem with ArcCurve.Arc

I think this is a special case where pylance is getting confused because the property name and the return type are the same word.

I retype the blender importer import_3dm. It’s a good exercise for testing types)

For now, apart from the Rhino tables, I changed
ArcCurve.Arc et LineCurve.Line

for converters/curve.py work

Is pycharm free and working well?

I haven’t used pycharm for a while. VS Code just got too good at dealing with python.

Until today, I had never really succeeded with rhino3dm, even if there are still holes in the copy I have, that changes everything! I can understand Nathan’s script.
I’m starting to see the possibilities offered by rhino3dm.py, I am happy!

I quickly typed import_3dm, Do you want me to send you the copy?

1 Like

What is import_3dm ?

You should probably make a PR for that repository if you have something to contribute.