fake-bpy-module
fake-bpy-module copied to clipboard
`draw_handler_add` - false negatives on passing `None` values
Example snippet:
import bpy
def draw_callback(*args, **kwargs):
print("Draw callback called with:")
print(" args:", args)
print(" kwargs:", kwargs)
# TypeError: Space.draw_handler_add() argument 3 must be tuple, not None
handler = bpy.types.SpaceView3D.draw_handler_add(
draw_callback,
None,
'WINDOW',
'POST_PIXEL'
)
It has no typing issues but results in an error on runtime: TypeError: Space.draw_handler_add() argument 3 must be tuple, not None.
False negative is caused by | None present in argument type.
@Andrej730 I could not understand the root cause of this issue. Is it possible from our side to fix this?
I don't know, I haven't investigated where optionality is coming from exactly - can't pinpoint whether it's fake-bpy issue or something's wrong with blender docs also.
But from the docs it seems there's nothing that suggest that those arguments are optional:
https://docs.blender.org/api/current/bpy.types.SpaceView3D.html
@Andrej730 Do you have expected typing? If so, we can handle this issue. If not, it is difficult to fix from our side.
Sure, overall argument types are correct, but there shouldn't be | None for any of those arguments.
Here are runtime tests:
- Passing
Noneascallbackresults inTypeError: first argument isn't callable - Passing
Noneasargs-Space.draw_handler_add() argument 3 must be tuple, not None - Passing
Noneasregion_type-TypeError: expected a string enum, not NoneType - Passing
Noneasdraw_type-TypeError: expected a string enum, not NoneType.
Thank you.
So, is removing | None the solution?
Indeed. Just uncertain about the cause.
Raised PR to fix this. https://projects.blender.org/blender/blender/pulls/139946
Blender patch is rejected. Will handle this by changing the code.