RNA enum properties support

This commit is contained in:
2026-09-21 11:18:10 +02:00
parent f575a84c13
commit f2efa629ba
8 changed files with 134 additions and 8 deletions
+17 -1
View File
@@ -603,6 +603,19 @@ def generate_types_stub(
structs: list[StructData], python_version: str = "3.11", doc: str = ""
) -> str:
"""Generate the complete bpy/types.pyi content."""
enum_aliases: dict[str, str] = {}
enum_property_aliases = {
"bl_space_type": "SpaceType",
"bl_region_type": "RegionType",
}
for struct in structs:
for prop in struct["properties"]:
alias_name = enum_property_aliases.get(prop["name"])
if alias_name is None or not prop["type"].startswith("Literal["):
continue
enum_aliases.setdefault(alias_name, prop["type"])
prop["type"] = alias_name
# Collect all type strings to detect needed imports
all_type_strs_parts: list[str] = []
for s in structs:
@@ -616,7 +629,7 @@ def generate_types_stub(
all_type_strs_parts.append(m["return_type"])
all_type_strs = " ".join(all_type_strs_parts)
typing_imports = ["Generic", "TypedDict", "TypeVar"]
typing_imports = ["Generic", "TypedDict", "TypeAlias", "TypeVar"]
if "Literal[" in all_type_strs:
typing_imports.append("Literal")
if re.search(r"\bSelf\b", all_type_strs):
@@ -657,6 +670,9 @@ def generate_types_stub(
'_T = TypeVar("_T")',
]
)
for alias_name, alias_type in enum_aliases.items():
parts.append("")
parts.append(f"{alias_name}: TypeAlias = {alias_type}")
sorted_structs = topological_sort_structs(structs)
inherited_map = collect_inherited_info(sorted_structs)