I wish to create a dataclass where one of the attributes will hold a function. It could be any function, so I won't know what parameters it will accept when the dataclass is used.
I see that python doesn't do strict typing, so the following code will work, but it technically is not correct. What is the correct way to declare my task attribute to be a function?
I see that python doesn't do strict typing, so the following code will work, but it technically is not correct. What is the correct way to declare my task attribute to be a function?
from dataclasses import dataclass @dataclass class Schedule: name: str task: str # <--- what should this be? interval: int def hello(name=None): print(f"Hello {name}!") def hello2(name, age): print(f"Hello {name}! You are {age} years old.") job1 = Schedule("Greeter", hello, 5) print(job1) print(job1.name) job1.task("Bob") job2 = Schedule("Age", hello2, 1) job2.task("Bob", 22)