Are type hints for the Python API available or if not are they planned?

Are type hints for the Python API available or if not are they planned?

tim.collins29V9X
Enthusiast Enthusiast
948 Views
5 Replies
Message 1 of 6

Are type hints for the Python API available or if not are they planned?

tim.collins29V9X
Enthusiast
Enthusiast

I observe that code suggestions in VS Code for Python are limited by the absence of type hints in the Fusion 360 interface libraries.  For the reader who wants background on type hints and suggestions, check out this link: typing — Support for type hints    

 

Enabling type hints makes mastering a new and complex API far easier, far safer, and frankly a lot more fun. Just hit "control-space" and you get the full list of functions and members that apply to that context and just have to pick one to have it pasted in without typos. Requiring an edit/compile/debug cycle to fix what ought to be a simple spell-check error is reminiscent of the 1970s when everyone used "vi" and was happy to spend months memorizing everything. I don't have the budget for that.

I can see the need to maintain backwards compatibility.  Python has it's significant issues here. That said, I believe this is so valuable that it would be worth maintaining a permanent version branch.

Does this already exist and I haven't found it yet? Are there plans to add this to the Python API for Fusion 360?

Accepted solutions (1)
949 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor
0 Likes
Message 3 of 6

tim.collins29V9X
Enthusiast
Enthusiast

I should have been more specific. I am suggesting that the four files core.py, cam.py, drawing.py, fusion.py all be modified -- by Autodesk -- to include "type hints".  I suspect that Autodesk either has this work on some Sprint backlog (or whatever) or has already announced it, or it was done years ago and I'm too new to know where to find out. Perhaps I could inspire the right person to help make it a reality?  As @kandennti demonstrated so well above we have the ability to use type hints and they are powerful. They ought be in those files.

 

On my Windows these four files are located in C:\Users\Tim\AppData\Roaming\Autodesk\Autodesk Fusion 360\API\Python\defs\adsk  and as mentioned above they are named core.py, cam.py, drawing.py, fusion.py

 

The URL I gave before had a typo, my apology. It should have been https://docs.python.org/3/library/typing.html  

Two concrete examples.  In core.py in class "Application" we have this source code at (in my version) line 330:

 

    def userInterface(self):
 
We could instead have:
 
    def userInterface(self) -> UserInterface:
 
We could also add hints to the API for improving the UX experience not to mention type safety for arguments. Say in fusion.py line 898

def pointContainment(self, point):
 
would be 
 
def pointContainment(self, Point: point)  -> PointContainment:
 

The type safety for composing arguments alone would be worth the trouble in my own opinion.

Is there a URL where future features a mentioned for the Fusion 360 Python API? That might end up being the only possible answer to my question.

 

Message 4 of 6

tim.collins29V9X
Enthusiast
Enthusiast

Thanks for the nice screen shots and explanations. I realize my question needed to be more specific and I tried to do that above.

Message 5 of 6

tim.collins29V9X
Enthusiast
Enthusiast

I think I found why type hints are missing from the 4 API files. This level of Python is a bit beyond what I was hoping to deal with. Any chance we could get Autodesk to release a version where the type hints are left in? Even if they might be confusing to some people?

 

Here is what I found.

 

VS Code debugging shows this file 

C:\Users\Tim\AppData\Roaming\Autodesk\Autodesk Fusion 360\API\Python\defs\adsk\core.py

 

# This file is automatically generated for code intellisense only.
# It does not reflect the actual implementation.

...

def allToolbarPanels(self):

 

However the actual code that is executed is in C:\Users\Tim\AppData\Local\Autodesk\webdeploy\production\96174d2c4918a1a613b00371fd422e0f30e1d187\Api\Python\packages\adsk\core.py instead shows

 

def _get_allToolbarPanels(self) -> "adsk::core::Ptr< adsk::core::ToolbarPanelList >":

 

and later in the same file

 

UserInterface.allToolbarPanels = property(UserInterface._get_allToolbarPanels, doc="Gets all of the toolbar panels. This returns all of the panels\navailable, regardless of which workspace or product they're associated with.")

 

 

def _get_allToolbarPanels(self) -> "adsk::core::Ptr< adsk::core::ToolbarPanelList >":

C:\Users\Tim\AppData\Local\Autodesk\webdeploy\production\96174d2c4918a1a613b00371fd422e0f30e1d187\Api\Python\packages\adsk\core.py

 

I am pretty sure that if VS Code encountered someObj.getAllToolbarPanels(). (hit spacebar) it would know the result was a ToolbarPanelList and so on. This would make learning the API wonderful.  I'd like this to be wonderful.

0 Likes
Message 6 of 6

BrianEkins
Mentor
Mentor
Accepted solution

I know there are some fixes in this area coming.  I'm not sure if this specific issue is addressed but I agree that it is something that would be useful and hopefully it is coming.  Thanks for pointing it out.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes