如何在数据类中拥有一个功能的现场占位符

发布于 2025-02-07 17:19:00 字数 240 浏览 2 评论 0原文

考虑一下休假:

我有一个数据类,其中一个字段将来会收到一个功能。

我应该将哪种类型声明变量? 另外,我将其设置为init值,这是正确的事情吗?

@dataclass
class SystemIpMember:
    name: str
    ip: str
    verify_func: ??? = None
    online: bool = False

谢谢!

Consider the fallowing:

I have a data class and one of the fields will receive a function in the future.

What type should I declarer the variable?
Also, I set a value of None as the init value, is that the right thing to do?

@dataclass
class SystemIpMember:
    name: str
    ip: str
    verify_func: ??? = None
    online: bool = False

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2025-02-14 17:19:00

正如麦克斯所说的那样,我使用了“可叫”

@dataclass
class SystemIpMember:
    name: str
    ip: str
    verify_func: Callable = None
    online: bool = False

As Max Stated, I used "Callable"

@dataclass
class SystemIpMember:
    name: str
    ip: str
    verify_func: Callable = None
    online: bool = False
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文