本文整理汇总了Python中setuptools.compat.func_code方法的典型用法代码示例。如果您正苦于以下问题:Python compat.func_code方法的具体用法?Python compat.func_code怎么用?Python compat.func_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类setuptools.compat
的用法示例。
在下文中一共展示了compat.func_code方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExtractConst
# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def testExtractConst(self):
if not hasattr(dep, 'extract_constant'):
# skip on non-bytecode platforms
return
def f1():
global x, y, z
x = "test"
y = z
fc = func_code(f1)
# unrecognized name
self.assertEqual(dep.extract_constant(fc,'q', -1), None)
# constant assigned
self.assertEqual(dep.extract_constant(fc,'x', -1), "test")
# expression assigned
self.assertEqual(dep.extract_constant(fc,'y', -1), -1)
# recognized name, not assigned
self.assertEqual(dep.extract_constant(fc,'z', -1), None)
示例2: testExtractConst
# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def testExtractConst(self):
if not hasattr(dep, 'extract_constant'):
# skip on non-bytecode platforms
return
def f1():
global x, y, z
x = "test"
y = z
fc = func_code(f1)
# unrecognized name
assert dep.extract_constant(fc,'q', -1) is None
# constant assigned
dep.extract_constant(fc,'x', -1) == "test"
# expression assigned
dep.extract_constant(fc,'y', -1) == -1
# recognized name, not assigned
dep.extract_constant(fc,'z', -1) is None
示例3: __patched_linecache_getlines
# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def __patched_linecache_getlines(self, filename, module_globals=None):
m = self.__LINECACHE_FILENAME_RE.match(filename)
if m and m.group('name') == self.test.name:
example = self.test.examples[int(m.group('examplenum'))]
return example.source.splitlines(True)
elif func_code(self.save_linecache_getlines).co_argcount > 1:
return self.save_linecache_getlines(filename, module_globals)
else:
return self.save_linecache_getlines(filename)
示例4: _find_lineno
# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def _find_lineno(self, obj, source_lines):
"""
Return a line number of the given object's docstring. Note:
this method assumes that the object has a docstring.
"""
lineno = None
# Find the line number for modules.
if inspect.ismodule(obj):
lineno = 0
# Find the line number for classes.
# Note: this could be fooled if a class is defined multiple
# times in a single file.
if inspect.isclass(obj):
if source_lines is None:
return None
pat = re.compile(r'^\s*class\s*%s\b' %
getattr(obj, '__name__', '-'))
for i, line in enumerate(source_lines):
if pat.match(line):
lineno = i
break
# Find the line number for functions & methods.
if inspect.ismethod(obj): obj = im_func(obj)
if inspect.isfunction(obj): obj = func_code(obj)
if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code
if inspect.iscode(obj):
lineno = getattr(obj, 'co_firstlineno', None)-1
# Find the line number where the docstring starts. Assume
# that it's the first line that begins with a quote mark.
# Note: this could be fooled by a multiline function
# signature, where a continuation line begins with a quote
# mark.
if lineno is not None:
if source_lines is None:
return lineno+1
pat = re.compile('(^|.*:)\s*\w*("|\')')
for lineno in range(lineno, len(source_lines)):
if pat.match(source_lines[lineno]):
return lineno
# We couldn't find the line number.
return None
######################################################################
## 5. DocTest Runner
######################################################################