Blender's use of annotations is a bit unusual in the Python world.
Currently, this is not a problem, but it will be in Python 3.10.
The way annotations work is different in Python 3.10. The new behaviors
can be activated with from __future__ import annotations in the first
source code line.
The specific issue can be seen when running the following code snippet:
from __future__ import annotations import bpy from bpy.props import StringProperty class MyOperator(bpy.types.Operator): bl_idname = "object.my_operator" bl_label = "My Operator" my_prop: StringProperty() def execute(self, context): return {'FINISHED'} import typing hints = typing.get_type_hints(MyOperator) print(hints)
Traceback (most recent call last):
File "/home/jacques/Downloads/future_annotations.blend/Text", line 15, in <module>
File "/home/jacques/blender-git/build_linux/bin/2.91/python/lib/python3.7/typing.py", line 978, in get_type_hints
value = _eval_type(value, base_globals, localns)
File "/home/jacques/blender-git/build_linux/bin/2.91/python/lib/python3.7/typing.py", line 263, in _eval_type
return t._evaluate(globalns, localns)
File "/home/jacques/blender-git/build_linux/bin/2.91/python/lib/python3.7/typing.py", line 469, in _evaluate
is_argument=self.__forward_is_argument__)
File "/home/jacques/blender-git/build_linux/bin/2.91/python/lib/python3.7/typing.py", line 142, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Forward references must evaluate to types. Got (<built-in function StringProperty>, {}).The typing.get_type_hints function expects that all annotations have
types on the right side. However, currently StringProperty() returns
a tuple (bpy.props.StringProperty, {}), which is not a type.
This patch implements changes the return type of StringProperty() to
be a new type. Obviously, this is a bit hacky and it's kind of a bummer
that this change is necessary. This is my first attempt on solving this,
so maybe there are better solutions.
Fixing this is not very urgent but should be done in time. It should
be noted that fixing this will break some third party addons, but the fixes
should be relatively simple.
Also see: