5353 "GlobalSettings" , # redefined explicitly
5454]
5555
56- # These classes are deferred to the very end of the dump, so that they have access to all the types
57- DEFERRED_CLASSES : List [str ] = [
58- "ServiceProvider" ,
59- # The following must be deferred as they rely on ServiceProvider
60- "DataModel" ,
61- "GenericSettings" ,
62- "AnalysticsSettings" ,
63- "UserSettings" ,
64- # Plugin is deferred after its items are declared
65- "Plugin" ,
66- ]
67-
6856# Methods / Properties ignored in classes. Commonly used to add corrections
6957IGNORED_MEMBERS = {
7058 "Instance" : [
432420type QFont = string
433421type FloatCurveKey = any
434422type RotationCurveKey = any
435- type Instance = any
436423
437424declare class Enum
438425 function GetEnumItems(self): { any }
@@ -759,7 +746,7 @@ def resolveParameterList(params: List[ApiParameter]):
759746 return ", " .join (map (resolveParameter , params ))
760747
761748
762- def resolveReturnType (member : Union [ApiFunction , ApiCallback ]):
749+ def resolveReturnType (member : Union [ApiFunction , ApiCallback ]) -> str :
763750 return (
764751 "(" + ", " .join (map (resolveType , member ["TupleReturns" ])) + ")"
765752 if "TupleReturns" in member
@@ -769,7 +756,11 @@ def resolveReturnType(member: Union[ApiFunction, ApiCallback]):
769756
770757def filterMember (klassName : str , member : ApiMember ):
771758 if not INCLUDE_DEPRECATED_METHODS and (
772- ("Tags" in member and "Deprecated" in member ["Tags" ])
759+ (
760+ "Tags" in member
761+ and member ["Tags" ] is not None
762+ and "Deprecated" in member ["Tags" ]
763+ )
773764 or ("Deprecated" in member and member ["Deprecated" ])
774765 ):
775766 return False
@@ -789,16 +780,21 @@ def filterMember(klassName: str, member: ApiMember):
789780 return True
790781
791782
792- def declareClass (klass : ApiClass ):
793- if klass ["Name" ] in IGNORED_INSTANCES :
794- return ""
795-
796- if (
783+ def shouldExcludeAsDeprecated (klass : ApiClass ):
784+ return (
797785 not INCLUDE_DEPRECATED_METHODS
798786 and "Tags" in klass
787+ and klass ["Tags" ] is not None
799788 and "Deprecated" in klass ["Tags" ]
800789 and not klass ["Name" ] in OVERRIDE_DEPRECATED_REMOVAL
801- ):
790+ )
791+
792+
793+ def declareClass (klass : ApiClass ) -> str :
794+ if klass ["Name" ] in IGNORED_INSTANCES :
795+ return ""
796+
797+ if shouldExcludeAsDeprecated (klass ):
802798 return ""
803799
804800 out = "declare class " + klass ["Name" ]
@@ -840,15 +836,15 @@ def declareService(service: str):
840836 )
841837
842838 out += "" .join (sorted (memberDefinitions ))
843-
844839 out += "end"
845840
846841 return out
847842
848843
849844def printEnums (dump : ApiDump ):
850- enums : defaultdict [str , List [str ]] = defaultdict ( list )
845+ enums : dict [str , List [str ]] = {}
851846 for enum in dump ["Enums" ]:
847+ enums [enum ["Name" ]] = []
852848 for item in enum ["Items" ]:
853849 enums [enum ["Name" ]].append (item ["Name" ])
854850
@@ -875,24 +871,18 @@ def printEnums(dump: ApiDump):
875871
876872
877873def printClasses (dump : ApiDump ):
878- # Forward declare all the types
874+ # Forward declare "deprecated" classes in case they are still used
879875 for klass in dump ["Classes" ]:
880- if klass ["Name" ] in IGNORED_INSTANCES :
881- continue
882- if klass ["Name" ] != "Instance" :
876+ if shouldExcludeAsDeprecated (klass ):
883877 print (f"type { klass ['Name' ]} = any" )
884878
885879 for klass in dump ["Classes" ]:
886- if klass ["Name" ] in DEFERRED_CLASSES or klass [ "Name" ] in IGNORED_INSTANCES :
880+ if klass ["Name" ] in IGNORED_INSTANCES :
887881 continue
888882
889883 print (declareClass (klass ))
890884 print ()
891885
892- for klassName in DEFERRED_CLASSES :
893- print (declareClass (CLASSES [klassName ]))
894- print ()
895-
896886
897887def printDataTypes (types : List [DataType ]):
898888 for klass in types :
@@ -1064,7 +1054,7 @@ def loadClassesIntoStructures(dump: ApiDump):
10641054 continue
10651055
10661056 isCreatable = True
1067- if "Tags" in klass :
1057+ if "Tags" in klass and klass [ "Tags" ] is not None :
10681058 if (
10691059 "Deprecated" in klass
10701060 and not INCLUDE_DEPRECATED_METHODS
@@ -1087,7 +1077,7 @@ def topologicalSortDataTypes(dataTypes: List[DataType]) -> List[DataType]:
10871077
10881078 dataTypeNames = {klass ["Name" ] for klass in dataTypes }
10891079
1090- def resolveClass (type : Union [ApiValueType , CorrectionsValueType ]):
1080+ def resolveClass (type : Union [ApiValueType , CorrectionsValueType ]) -> Optional [ str ] :
10911081 name = (
10921082 type ["Generic" ]
10931083 if "Generic" in type
0 commit comments