关于collections.py和_abcoll.py(python 2.7.3)中bootstrapping
发布时间:2020-12-20 13:29:53 所属栏目:Python 来源:网络整理
导读:我正在阅读收集模块的源代码. modue是两个文件的组合:collections.py和_abcoll.py. 这是模块的 doc,它包含源代码的链接. 在collections.py的开头: __all__ = ['Counter','deque','defaultdict','namedtuple','OrderedDict']# For bootstrapping reasons,th
我正在阅读收集模块的源代码. modue是两个文件的组合:collections.py和_abcoll.py.
这是模块的 doc,它包含源代码的链接. 在collections.py的开头: __all__ = ['Counter','deque','defaultdict','namedtuple','OrderedDict'] # For bootstrapping reasons,the collection ABCs are defined in _abcoll.py. # They should however be considered an integral part of collections.py. from _abcoll import * import _abcoll __all__ += _abcoll.__all__ ... 我不太明白实际的’引导原因’是什么,因为在_abcoll.py中: 6 DON'T USE THIS MODULE DIRECTLY! The classes here should be imported 7 via collections; they are defined here only to alleviate certain 8 bootstrapping issues. Unit tests are in test_collections. 9 """ 10 11 from abc import ABCMeta,abstractmethod 12 import sys 13 14 __all__ = ["Hashable","Iterable","Iterator",15 "Sized","Container","Callable",16 "Set","MutableSet",17 "Mapping","MutableMapping",18 "MappingView","KeysView","ItemsView","ValuesView",19 "Sequence","MutableSequence",20 ] ... _abc .__ all__包含此文件中的所有类定义,而在collections.py中,它从_abcoll导入*并将_abcoll .__ all__附加到它自己的__all__.我没有理解为什么这种方式可以“缓解某些引导问题”. 有什么想法吗?谢谢 解决方法
问题似乎是旧版本的os.py,例如
this one:
from _abcoll import MutableMapping # Can't use collections (bootstrap) 显然,集合间接需要os(可能用于模块末尾的测试,其中一些酸洗完成,也可能在其他地方),因此没有_abcoll模块就会存在循环依赖. (注意,在Python> = 3.3中,有一个单独的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |