Use collections.abc.Sequence instead of _Sequence alias in bpy.types
Same approach as fake-bpy-module: fully qualify all Sequence references as collections.abc.Sequence to avoid shadowing by bpy.types.Sequence. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
175b1bd7e5
commit
f1cfc8ccbd
@ -367,6 +367,26 @@ def generate_property_stub(
|
||||
result += f"{indent} ...\n"
|
||||
return result
|
||||
|
||||
# Writable properties with different getter/setter types need @property
|
||||
# (e.g. location: mathutils.Vector | Sequence[float] -> getter returns Vector,
|
||||
# setter accepts both)
|
||||
if " | " in prop["type"]:
|
||||
parts_list = [p.strip() for p in prop["type"].split(" | ")]
|
||||
getter_type = parts_list[0]
|
||||
setter_type = prop["type"]
|
||||
result = f"{indent}{property_decorator}\n"
|
||||
result += f"{indent}def {prop['name']}(self) -> {getter_type}:\n"
|
||||
if prop["description"]:
|
||||
desc = prop["description"].replace("\\", "\\\\").replace('"""', r"\"\"\"")
|
||||
if desc.endswith('"'):
|
||||
desc += " "
|
||||
result += f'{indent} """{desc}"""\n'
|
||||
else:
|
||||
result += f"{indent} ...\n"
|
||||
result += f"{indent}@{prop['name']}.setter\n"
|
||||
result += f"{indent}def {prop['name']}(self, value: {setter_type}) -> None: ...\n"
|
||||
return result
|
||||
|
||||
result = f"{indent}{prop['name']}: {prop['type']}\n"
|
||||
if prop["description"]:
|
||||
desc = prop["description"].replace("\\", "\\\\").replace('"""', r"\"\"\"")
|
||||
@ -577,11 +597,7 @@ def generate_types_stub(
|
||||
),
|
||||
]
|
||||
if "Sequence[" in all_type_strs:
|
||||
# Use fully qualified import to avoid shadowing by bpy.types.Sequence
|
||||
# (the video sequencer strip type)
|
||||
imports.append("import collections")
|
||||
imports.append("import collections.abc")
|
||||
imports.append("from collections.abc import Sequence as _Sequence")
|
||||
if "mathutils." in all_type_strs:
|
||||
imports.append("import mathutils")
|
||||
|
||||
@ -612,8 +628,9 @@ def generate_types_stub(
|
||||
result = "\n".join(parts)
|
||||
class_names = {s["name"] for s in structs}
|
||||
result = strip_self_module_prefix(result, "bpy.types", class_names)
|
||||
# Replace bare Sequence[ with _Sequence[ to avoid shadowing by bpy.types.Sequence
|
||||
result = re.sub(r"(?<!\.)(?<!\w)\bSequence\[", "_Sequence[", result)
|
||||
# Qualify all bare Sequence[ to collections.abc.Sequence[ to avoid
|
||||
# shadowing by bpy.types.Sequence (the video sequencer strip type).
|
||||
result = re.sub(r"(?<!\.)(?<!\w)\bSequence\[", "collections.abc.Sequence[", result)
|
||||
# Qualify bare "object" in type annotations to avoid shadowing by
|
||||
# properties named "object" (e.g. Context.object: Object).
|
||||
result = re.sub(r"(?<=: )object\b", "builtins.object", result)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user