Faulty Enum Types

Faulty Enum Types

felix85SA3
Participant Participant
413 Views
2 Replies
Message 1 of 3

Faulty Enum Types

felix85SA3
Participant
Participant

I'm new to Python and used to strict type checking, so I just set up my VSCode and found that the enumeration types that are used throughout the definition files (%appdata%\Autodesk\Autodesk Fusion 360\API\Python\defs\fusion.py) lack Enum-inheritance

 

E.g. createInput is defined as:

def createInput(self, profile: core.Base, operation: FeatureOperations) -> ExtrudeFeatureInput:

But the class FeatureOperations reads:

class FeatureOperations():
    """
    List of the different operations a feature can perform.
    """
    def __init__(self):
        pass
    JoinFeatureOperation = 0
    CutFeatureOperation = 1
    IntersectFeatureOperation = 2
    NewBodyFeatureOperation = 3
    NewComponentFeatureOperation = 4

Which yields an error

Argument of type "int" cannot be assigned to parameter "operation" of type "FeatureOperations" in function "createInput"
  "int" is incompatible with "FeatureOperations"

 

According to my understanding the following would fix the issue:

from enum import Enum

class FeatureOperations(Enum):
    # ...

 

 Am I missing something?

414 Views
2 Replies
Replies (2)
Message 2 of 3

cowboyEZ6F4
Observer
Observer

I've run into this exact same issue. Did you figure out a workaround, other than adding "# type: ignore" everywhere?

 

Fusion Python API maintainers - please fix this!

0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor

I think the problem you're referring to is a result of the Fusion API not using the Python Enum class, but instead defines enums using a standard class with variables with integer values that define the enum values. The reason for that is that Python Enums didn't exist in the language when the API was first released, and this was the workaround chosen. It would be beneficial if the API could be updated to utilize the new Python Enum class; however, I am unsure if that is possible without breaking all existing code that uses enums. I don't know if the possibility has been investigated or not.

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