Dessia-tech / dessia_common

GNU Lesser General Public License v2.1
1 stars 2 forks source link

Attach metadata to function #676

Closed younesdessia closed 7 months ago

younesdessia commented 7 months ago

**Note: for support questions, please use https://nextcloud.dessia.tech/call/hr9z9bif

is it more interesting to do like this to attach metadata to function, using annotations?

def set_decorated_function_metadata(function, type_: str, selector: str = None, serialize_data: bool = False,
                                    load_by_default: bool = False):
    function.__annotations__["type_"] = type_
    function.__annotations__["selector"] = selector
    function.__annotations__["serialize_data"] = serialize_data
    function.__annotations__["load_by_default"] = load_by_default
GhislainJ commented 7 months ago

No, __annotations__ is dictionary that gathers all info about the signature of the method, when it is typed. We actually use it to generate function schemas and the last thing we wan't to do is to pollute and modify it in some obscure context (decorated functions search).

The current solution is already an abuse of how python works and I would prefer if we had another one, but this whole "search and find decorated methods" is not how decorators are supposed to work, so we have to stick with that for the moment