V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
shellex
V2EX  ›  程序员

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

  •  
  •   shellex ·
    shellex · 2012-12-21 16:14:48 +08:00 · 8238 次点击
    这是一个创建于 4115 天前的主题,其中的信息可能已经有所发展或是发生改变。
    一切默认配置都很正常,系统库可以正常补全。不过对于项目中的类有一些问题:
    我现在有一个类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'>

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

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

    if 0: t=T()
    shellex
        4
    shellex  
    OP
       2012-12-21 16:57:15 +08:00
    @timonwong 确实可以,在当前scope可以找到类型…… 不过这个 trick 真是太 erratic 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3184 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 00:18 · PVG 08:18 · LAX 17:18 · JFK 20:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.