Fix mypy compatibility and add 5.0 conformance tests
- Qualify bare "object" as builtins.object in bpy.types to avoid shadowing by Context.object and similar properties - Use _Sequence alias import to fix mypy "collections.abc.Sequence not defined" - Filter out variables that clash with submodule re-exports (e.g. bpy.app) - Add 5.0 conformance tests from Blender 5.0 mathutils documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+14
-6
@@ -600,7 +600,9 @@ 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")
|
||||
|
||||
parts: list[str] = []
|
||||
if doc:
|
||||
@@ -629,10 +631,14 @@ 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)
|
||||
# Qualify all bare Sequence[ references to avoid shadowing by bpy.types.Sequence
|
||||
result = re.sub(
|
||||
r"(?<!\.)(?<!\w)\bSequence\[", "collections.abc.Sequence[", result
|
||||
)
|
||||
# Replace bare Sequence[ with _Sequence[ to avoid shadowing by bpy.types.Sequence
|
||||
result = re.sub(r"(?<!\.)(?<!\w)\bSequence\[", "_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)
|
||||
result = re.sub(r"(?<=\| )object\b", "builtins.object", result)
|
||||
result = re.sub(r"(?<=\[)object\b", "builtins.object", result)
|
||||
result = re.sub(r"(?<=-> )object\b", "builtins.object", result)
|
||||
return prune_unused_imports(result)
|
||||
|
||||
|
||||
@@ -755,11 +761,13 @@ def generate_module_stub(
|
||||
parts.append('_T = TypeVar("_T")')
|
||||
parts.append("")
|
||||
|
||||
# Variables
|
||||
# Variables (skip those that clash with submodule re-exports)
|
||||
sub_names = set(submodule_names or [])
|
||||
if module_data["variables"]:
|
||||
parts.append("")
|
||||
for var in module_data["variables"]:
|
||||
parts.append(generate_variable_stub(var))
|
||||
if var["name"] not in sub_names:
|
||||
parts.append(generate_variable_stub(var))
|
||||
|
||||
# Functions
|
||||
for func in module_data["functions"]:
|
||||
|
||||
Reference in New Issue
Block a user