什么是 Dropbox API (v2) 联合标签?
What is a Dropbox API (v2) Union Tag?
在开始使用 Python SDK 开发 Dropbox 应用程序时,我在概念上被 the AccessLevel documentation calls a union tag 绊倒了。 (这个概念超出了 AccessLevel class,但这似乎是一个很好的例子。)
我试图理解为什么 _tag
属性基本上看起来仅供内部使用。为什么,如果我想知道用户是否拥有编辑者、所有者或查看者权限——而且只能是其中之一——我似乎应该调用 is_owner()
、is_editor()
,和 is_viewer()
方法,直到我得到 True
响应。
我错过了什么?为什么只访问 _tag
属性并随心所欲不是一个好主意?
API 文档将 .tag
定义为:
The .tag field in an object identifies the subtype of a struct or selected member of a union.
Tagged union 似乎是一个通用概念,而不是特定于 Dropbox 的概念:
In computer science, a tagged union ... is a data structure used to hold a value that could take on several different, but fixed, types
维基百科进一步阐明了这种适用性:
Only one of the types can be in use at any one time, and a tag field explicitly indicates which one is in use. This is critical in defining recursive datatypes ... where it is necessary to distinguish multi-node subtrees and leaves.
Dropbox API 端点的一个很好的例子是 list_folder
其中 return 可以是文件或文件夹,即 .tag
可以取值 file
或 folder
.
我相信这对于强类型代码很有价值,其中 returned files/folders 被解析为 类.
在开始使用 Python SDK 开发 Dropbox 应用程序时,我在概念上被 the AccessLevel documentation calls a union tag 绊倒了。 (这个概念超出了 AccessLevel class,但这似乎是一个很好的例子。)
我试图理解为什么 _tag
属性基本上看起来仅供内部使用。为什么,如果我想知道用户是否拥有编辑者、所有者或查看者权限——而且只能是其中之一——我似乎应该调用 is_owner()
、is_editor()
,和 is_viewer()
方法,直到我得到 True
响应。
我错过了什么?为什么只访问 _tag
属性并随心所欲不是一个好主意?
API 文档将 .tag
定义为:
The .tag field in an object identifies the subtype of a struct or selected member of a union.
Tagged union 似乎是一个通用概念,而不是特定于 Dropbox 的概念:
In computer science, a tagged union ... is a data structure used to hold a value that could take on several different, but fixed, types
维基百科进一步阐明了这种适用性:
Only one of the types can be in use at any one time, and a tag field explicitly indicates which one is in use. This is critical in defining recursive datatypes ... where it is necessary to distinguish multi-node subtrees and leaves.
Dropbox API 端点的一个很好的例子是 list_folder
其中 return 可以是文件或文件夹,即 .tag
可以取值 file
或 folder
.
我相信这对于强类型代码很有价值,其中 returned files/folders 被解析为 类.