我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用__future__._Feature()。
def is_future_feature(object): """ Return True if C{object} results from a C{from __future__ import feature} statement. """ # Guard from unexpected implementation changes of the __future__ module. global __future_check_works if __future_check_works is not None: if __future_check_works: import __future__ return isinstance(object, __future__._Feature) else: return False else: __future_check_works = True try: return is_future_feature(object) except: __future_check_works = False log.warning("Troubles inspecting __future__. Python implementation" " may have been changed.") return False
def testAllExported(self): """Test that all public attributes not imported are in __all__.""" missing_attributes = [] for attribute in dir(self.MODULE): if not attribute.startswith('_'): if attribute not in self.MODULE.__all__: attribute_value = getattr(self.MODULE, attribute) if isinstance(attribute_value, types.ModuleType): continue # pylint: disable=protected-access if isinstance(attribute_value, __future__._Feature): continue missing_attributes.append(attribute) if missing_attributes: self.fail('%s are not modules and not defined in __all__.' % missing_attributes)
def test_names(self): # Verify that all_feature_names appears correct. given_feature_names = features[:] for name in dir(__future__): obj = getattr(__future__, name, None) if obj is not None and isinstance(obj, __future__._Feature): self.assertTrue( name in given_feature_names, "%r should have been in all_feature_names" % name ) given_feature_names.remove(name) self.assertEqual(len(given_feature_names), 0, "all_feature_names has too much: %r" % given_feature_names)