marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy

Home Page:https://vedo.embl.es

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return type annotations for vedo functions

jo-mueller opened this issue · comments

Hi @marcomusy ,

long time no hear :) I'm still low-key working on the idea I pitched to you last year August at the NEUBIAS conference in Dresden, which basically revolves around harvesting all vedo functions to be automatically wrapped for usage in Napari. This would be awesome because

  • no wrapper functions would be needed to maintained
  • all GUIs automatically created from function definitions alone

I have some sort of a working version, but what's making my life a bit hard is the lack of type annotations in vedo, specifically return type annotations. For starters, I wanted to limit myself to harvesting functions that take a mesh as input and return another mesh (as opposed to functions that color a mesh, or measure something on the vertices, etc).

What would make my life much easier, would be, instrad of vedo mesh functions being defined like this

def decimate(self, parameters):
  ...
  return mesh

but rather like this:

from typing import Self
def decimate(self, parameters) -> Self:
  ...
  return mesh

The return type annotation in the latter case could be used to mark functions that do return meshes and nothing else. Similarly, functions consuming a mesh and returning a pointcloud could be annotated like this:

def points_from_mesh(mesh, parameters) -> vedo.Points:
  ....
  return points

Would you be (in principle) be open to such changes? I would take the PR writing to myself, of course :)

Hi Johannes! sure i'm completely open to the idea.
Note that in the master version I had already added annotations but I didn't of from typing import Selfso feel free to make the changes you think are appropriate!

HI @marcomusy, thanks for the hint, I totally hadn't seen it, cool work! I think the current return type annotations ("Mesh", "Points", etc) are totally sufficient for what I am trying to do :) I'll close this issue then :)

Also, did you just give me some sort of semi-maintainer status? 😲 (I cannot see my level of permissions)

Fantastic. I will probably update what I did with the Self thing you mentioned which seems the right thing to do..

Yes I added you to Collaborators so you can push directly any changes (i think you are a vedo expert by now!)

@marcomusy thanks! Will proceed with a few type annotations next then. Napari has a few issues deciphering whether some inputs are supposed to be floats, integers, etc.