• 请不要在回答技术问题时复制粘贴 AI 生成的内容
shellex
V2EX  ›  程序员

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

  •  
  •   shellex ·
    shellex · Dec 21, 2012 · 9131 views
    This topic created in 4902 days ago, the information mentioned may be changed or developed.
    一切默认配置都很正常,系统库可以正常补全。不过对于项目中的类有一些问题:
    我现在有一个类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 replies    1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       Dec 21, 2012
    很正常啊,do(t) 并不知道 t 的具体类型信息
    main中能是因为j和t的类型都确定了。
    shellex
        2
    shellex  
    OP
       Dec 21, 2012
    @timonwong 那怎么办呢。应该有不少这样的情况才是啊。
    timonwong
        3
    timonwong  
       Dec 21, 2012   ❤️ 1
    你试试这个trick:

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

    if 0: t=T()
    shellex
        4
    shellex  
    OP
       Dec 21, 2012
    @timonwong 确实可以,在当前scope可以找到类型…… 不过这个 trick 真是太 erratic 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2189 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:12 · PVG 00:12 · LAX 09:12 · JFK 12:12
    ♥ Do have faith in what you're doing.