在Python项目中使用SublimeCodeIntel出现的补全问题

2012-12-21 16:14:48 +08:00
 shellex
一切默认配置都很正常,系统库可以正常补全。不过对于项目中的类有一些问题:
我现在有一个类T在文件t.py中,有一个类J在文件j.py中,J有方法do(t)接受T类型的参数。
然后我在main.py中这样写:

if __name__ == '__main__':
j = J()
t = T()
j.do(t)

在main.py中按.时是可以弹出j和t的成员的,但是在j.py的do函数中无法补全t的成员。在~/.codeintel/codeintel.log中有如下错误

Done 'Python' CodeIntel! Full CodeIntel took 1ms
Doing CodeIntel for 'Python' (hold on)...
eval 't' at J.py#172 <Trigger 'python-complete-object-members' at 7170>
start scope is (<blob 'J'>, ['J', 'do'])
find 't ...' starting at (<blob 'j'>, ['J', 'do']):
is 't' accessible on (<blob 'j'>, ['J', 'do'])? yes: <argument 't'>
evaluating 't' at J.py#172: no type-inference info for <argument 't'>
done eval: eval error
Done 'Python' CodeIntel! Full CodeIntel took 10ms
+ Warning: evaluating 't' at J.py#172: no type-inference info for <argument 't'>

请问有遇到类似问题的同学么,怎么解决好?
8267 次点击
所在节点    程序员
4 条回复
timonwong
2012-12-21 16:38:23 +08:00
很正常啊,do(t) 并不知道 t 的具体类型信息
main中能是因为j和t的类型都确定了。
shellex
2012-12-21 16:44:24 +08:00
@timonwong 那怎么办呢。应该有不少这样的情况才是啊。
timonwong
2012-12-21 16:49:31 +08:00
你试试这个trick:

http://stackoverflow.com/a/1681587/1745982

if 0: t=T()
shellex
2012-12-21 16:57:15 +08:00
@timonwong 确实可以,在当前scope可以找到类型…… 不过这个 trick 真是太 erratic 了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/55485

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX