I don’t understand this recommendation, which also cites PEP-526, which it basically kinda breaks at the same time in the example? The valid annotation syntax is: var: type = value
their recommendation is: var : bpy.props.WhateverPropert(arg1=x, arg2=y)
This isnt particularly what spec talks about and this also will plague __annotations__ with nonsense like tuple(func, {k,v}) and it will break linters and type checkers.
Quote from Jake Bailey, Pyright/Pylance author
Unless I’m mistaken, function calls like this shouldn’t be legal in type annotations. Type annotations are meant to be static only, and future releases of Python won’t evaluate them at all anymore. I don’t believe we really try and handle this.
I’m all for type annotations, just not like, err, that. Can someone explain grand logic and idea behind this?
The problem is that it WILL have to change when next X version of python will stop evaluating them. First, it will be just bleeding-edge users reporting issues with these recommendations, then, when Blender switches to new python backend - it will affect everyone.
Here is a quick way to to see the issue in practice (without any addons):
Add from __future__ import annotations as first import statement in node.py.
Start Blender.
See the new error message in the terminal ValueError: NODE_OT_add_search.bl_property 'node_item' not found.
Blender could probably still use annotations, it would just have to force Python to evaluate them I believe. I don’t know what’s the best solution to this yet (breaking the api in such a fundamental way has a large cost).
If you cant have proper types for annotations in any foreseeable future until you rewrite whole thing to comply with annotations usefulness - don’t use them, simple as that. Better do it old way, then have half-broken in-between, for now.