I expected to be able to iterate over collections w/o running into type errors, however I am seeing this:
The problem is that the collection type is declared as a union as opposed to an intersection type. It's a bit more obvious in this error message:
I am new to mypy but from a bit of research it doesn't appear like they support intersection types just yet, but I played around with it and the desired type can be achieved by doing e.g.:
class ObjectCollection(
typing.Sequence[bpy.types.Object],
typing.Mapping[str, bpy.types.Object],
# HOWEVER, cannot enable these due to incompatible .items() declarations
# bpy.types.SceneObjects,
# bpy.types.bpy_prop_collection
):
pass
objects: ObjectCollection = ...
o = objects.get("foo")
So I am not sure what's the best approach but it looks like we'd have to generate class stubs based off all the things that go into the union and resolve mismatches...
Expected behavior
I expected to be able to iterate over collections w/o running into type errors, however I am seeing this:
The problem is that the collection type is declared as a union as opposed to an intersection type. It's a bit more obvious in this error message:
I am new to mypy but from a bit of research it doesn't appear like they support intersection types just yet, but I played around with it and the desired type can be achieved by doing e.g.:
So I am not sure what's the best approach but it looks like we'd have to generate class stubs based off all the things that go into the union and resolve mismatches...