python result函数_Python os 模块,stat_result() 实例源码 - 编程字典

def find_syntax_node_name(evaluator, python_object):

try:

python_object = _get_object_to_check(python_object)

path = inspect.getsourcefile(python_object)

except TypeError:

# The type might not be known (e.g. class_with_dict.__weakref__)

return None, None

if path is None or not os.path.exists(path):

# The path might not exist or be e.g. .

return None, None

module = _load_module(evaluator, path, python_object)

if inspect.ismodule(python_object):

# We don't need to check names for modules, because there's not really

# a way to write a module in a module in Python (and also __name__ can

# be something like ``email.utils``).

return module, path

try:

name_str = python_object.__name__

except AttributeError:

# Stuff like python_function.__code__.

return None, None

if name_str == '':

return None, None # It's too hard to find lambdas.

# Doesn't always work (e.g. os.stat_result)

try:

names = module.get_used_names()[name_str]

except KeyError:

return None, None

names = [n for n in names if n.is_definition()]

try:

code = python_object.__code__

# By using the line number of a code object we make the lookup in a

# file pretty easy. There's still a possibility of people defining

# stuff like ``a = 3; foo(a); a = 4`` on the same line, but if people

# do so we just don't care.

line_nr = code.co_firstlineno

except AttributeError:

pass

else:

line_names = [name for name in names if name.start_pos[0] == line_nr]

# There's a chance that the object is not available anymore, because

# the code has changed in the background.

if line_names:

return line_names[-1].parent, path

# It's really hard to actually get the right definition, here as a last

# resort we just return the last one. This chance might lead to odd

# completions at some points but will lead to mostly correct type

# inference, because people tend to define a public name in a module only

# once.

return names[-1].parent, path

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值