Skip to content

How to add attributes to Callable? #3882

Closed
@vitawasalreadytaken

Description

@vitawasalreadytaken

I have a simple decorator that just sets an attribute on a function and returns it. The closest I got to checking this is creating a subclass of Callable and adding the attribute to it:

from typing import Callable, cast

class RemoteCallable(Callable):
	rpc_name: str = None

def remote(f: Callable) -> RemoteCallable:
	''' Decorator marking a function as callable via the RPC system. '''
	f = cast(RemoteCallable, f)
	f.rpc_name = f.__name__
	return f

However, this fails with rpc.py:3: error: Invalid base class. What can I do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions