當前位置: 首頁>>代碼示例>>Python>>正文


Python __future__.all_feature_names方法代碼示例

本文整理匯總了Python中__future__.all_feature_names方法的典型用法代碼示例。如果您正苦於以下問題:Python __future__.all_feature_names方法的具體用法?Python __future__.all_feature_names怎麽用?Python __future__.all_feature_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在__future__的用法示例。


在下文中一共展示了__future__.all_feature_names方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _makeAST

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
def _makeAST(f):
    # Need to look at the flags used to compile the original function f and
    # pass these same flags to the compile() function. This ensures that
    # syntax-changing __future__ imports like print_function work correctly.
    orig_f_co_flags = f.__code__.co_flags
    # co_flags can contain various internal flags that we can't pass to
    # compile(), so strip them out here
    valid_flags = 0
    for future_feature in __future__.all_feature_names:
        feature = getattr(__future__, future_feature)
        valid_flags |= feature.compiler_flag
    s = inspect.getsource(f)
    s = _dedent(s)
    # use compile instead of ast.parse so that additional flags can be passed
    flags = ast.PyCF_ONLY_AST | (orig_f_co_flags & valid_flags)
    tree = compile(s, filename='<unknown>', mode='exec',
        flags=flags, dont_inherit=True)
    # tree = ast.parse(s)
    tree.sourcefile = inspect.getsourcefile(f)
    tree.lineoffset = inspect.getsourcelines(f)[1] - 1
    return tree 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:23,代碼來源:_util.py

示例2: IMPORTFROM

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
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) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:33,代碼來源:checker.py

示例3: _all_future_flags

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
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 
開發者ID:has2k1,項目名稱:plydata,代碼行數:9,代碼來源:eval.py

示例4: _extract_future_flags

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
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 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:13,代碼來源:doctest24.py

示例5: test_names

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test___future__.py

示例6: IMPORTFROM

# 需要導入模塊: import __future__ [as 別名]
# 或者: from __future__ import all_feature_names [as 別名]
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)
                if alias.name == 'annotations':
                    self.annotationsFutureEnabled = True
            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) 
開發者ID:PyCQA,項目名稱:pyflakes,代碼行數:35,代碼來源:checker.py


注:本文中的__future__.all_feature_names方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。