我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用__future__.all_feature_names()。
def _extract_future_flags(globs): """ Return the compiler-flags associated with the future features that have been imported into the given namespace (globs). """ flags = 0 for fname in __future__.all_feature_names: feature = globs.get(fname, None) if feature is getattr(__future__, fname): flags |= feature.compiler_flag return flags
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)
def IMPORTFROM(self, node): if node.module == '__future__': if not self.futuresAllowed: self.report(messages.LateFutureImport, node, [n.name for n in node.names]) else: self.futuresAllowed = False module = ('.' * node.level) + (node.module or '') for alias in node.names: name = alias.asname or alias.name if node.module == '__future__': importation = FutureImportation(name, node, self.scope) if alias.name not in __future__.all_feature_names: self.report(messages.FutureFeatureNotDefined, node, alias.name) elif alias.name == '*': # Only Python 2, local import * is a SyntaxWarning if not PY2 and not isinstance(self.scope, ModuleScope): self.report(messages.ImportStarNotPermitted, node, module) continue self.scope.importStarred = True self.report(messages.ImportStarUsed, node, module) importation = StarImportation(module, node) else: importation = ImportationFrom(name, node, module, alias.name) self.addBinding(node, importation)
def _all_future_flags(): flags = 0 for feature_name in __future__.all_feature_names: feature = getattr(__future__, feature_name) if feature.getMandatoryRelease() > sys.version_info: flags |= feature.compiler_flag return flags