下面是SqlAlchemy的一部分,我试图找出这是如何有效的Python语法。我知道代码是有效的,我只是想了解这里在做什么,以及它是如何有效的。这些不是嵌套类,而是独立类。我本以为在每个类声明之后都会有一个pass,但我很确定它的不存在是有意义的。你知道吗
class InstrumentedList(list):
"""An instrumented version of the built-in list."""
class InstrumentedSet(set):
"""An instrumented version of the built-in set."""
class InstrumentedDict(dict):
"""An instrumented version of the built-in dict."""
__canned_instrumentation = {
list: InstrumentedList,
set: InstrumentedSet,
dict: InstrumentedDict,
}
__interfaces = {
list: (
{'appender': 'append', 'remover': 'remove',
'iterator': '__iter__'}, _list_decorators()
),
set: ({'appender': 'add',
'remover': 'remove',
'iterator': '__iter__'}, _set_decorators()
),
# decorators are required for dicts and object collections.
dict: ({'iterator': 'values'}, _dict_decorators()) if util.py3k
else ({'iterator': 'itervalues'}, _dict_decorators()),
}
只要类定义中有某物,它就是有效的python语法。你知道吗
例如:
这没关系,因为类定义中有一些东西(在本例中是docstring,可以通过
__doc__
属性访问)。你知道吗但是,类定义中没有任何内容是无效语法:
运行此操作时,将生成输出:
相关问题 更多 >
编程相关推荐