Skip to content

sebthom.de

Menu
  • Home
  • Über mich
  • Impressum
    • Datenschutzerklärung
  • Gästebuch
Menu

Leveraging PyDev’s auto-completion for indirectly created objects

Posted on Samstag, der 20. Februar 2010Dienstag, der 18. Dezember 2012 by sebthom

This is just a quick tip how to enable auto completion in PyDev for indirectly created objects.

By default, PyDev has no problems in presenting you the possible object attributes and methods on a variable if that variable gets a new object instance assigned directly in the code.

For example, when you first type …

mybook = Book()

… and in the next line you enter …

mybook.

… PyDev will dutifully present you the statically declared features for the Book class in a popup.

If you however get that Book instance as the result of another method, e.g. …

mybook = bookstore.findBook("foobar")

… PyDev currently seems to be helpless.

Because of Python’s dynamic nature it is of course a bit harder for an IDE to figure out what kind of objects may a method. But PyDev could for example honor the @return / @rtype PyDoc annotations (which you can add to the findBook’s method declaration) but currently it just does not.

To still have auto-completion you have two options:

  1. Temporarily instantiate a Book object in the code.
    mybook = Book()
    mybook = bookstore.findBook("foobar")
    mybook. #--> now you have auto completion
    

    This has the drawback, that if you forget to remove the first line before you finish coding an unneccessary Book instance will be created on every execution during runtime.

  2. Use an assertion to ensure that the mybook variable contains an object of type Book
    mybook = bookstore.findBook("foobar")
    assert isinstance(mybook, Book)
    mybook. #--> now you have auto completion
    

5 thoughts on “Leveraging PyDev’s auto-completion for indirectly created objects”

  1. Pingback: Python:Eclipse pydev auto-suggestions don't work in some cases – IT Sprite
  2. Erick sagt:
    Mittwoch, der 9. Oktober 2013 um 21:06 Uhr

    PyDev now (as of 2.8.0) does check @rtype or :rtype (epydoc/sphinx) in docstrings!

  3. Michael sagt:
    Mittwoch, der 25. April 2012 um 22:54 Uhr

    assert + pydev = dreamy
    Thanks!

  4. Bitsprocket sagt:
    Sonntag, der 22. Januar 2012 um 21:20 Uhr

    Another method is to cast the object back to its type:

    mybook = bookstore.findBook(“foobar”)
    mybook = book(mybook)

    Or more simply:

    mybook = book(bookstore.findBook(“foobar”))

  5. charles sagt:
    Donnerstag, der 13. Mai 2010 um 13:33 Uhr

    Thank you ! Exactly the thing that i need !

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Kategorien

  • Blog (1)
  • IT (21)
    • Entwicklung (16)
      • Java (7)
      • Jython (4)
      • Visual Basic (5)
    • Linux (3)
    • WebSphere Application Server (1)
    • WebSphere Portal (2)
    • Windows (1)
  • My Freeware (2)
  • My Music (3)

Neueste Beiträge

  • Logging WebSphere API calls in wsadmin scripts
  • [Solved] Windows 7 “Safely Remove Hardware” pop-up menu horrendously slow
  • Bash: Capturing stderr in a variable while still printing to the console.
  • Configuring EMF Teneo with Hibernate, Commons DBCP, Spring Hibernate Transaction Manager, and the OpenSessionInViewFilter
  • Using EMF ECore model objects with Wicket components
  • Installing Tomcat 6 on Debian Squeeze
  • Leveraging PyDev’s auto-completion for indirectly created objects
  • OVal 1.40 released
  • Installing WebSphere Portal in a local network
  • Comparing version numbers in Jython / Python

Blogroll

  • E L S U A
  • elektrofever.de
  • OVal
  • Sweettt.com
  • Twins’ Running Blog

Neueste Kommentare

  • Annibale bei Visual Basic – Multiple Undos Class v2.04
  • Annibale bei Visual Basic – Multiple Undos Class v2.04
  • koliko2k3 bei Gästebuch
  • hdkid bei MyPad v1.1.6 – ein PHP Editor
  • Luis Diego Villarreal bei Excel – VBA Timer Example v1.0.1

Archive

  • Juni 2014
  • Mai 2012
  • Januar 2011
  • Oktober 2010
  • September 2010
  • März 2010
  • Februar 2010
  • September 2009
  • Juli 2009
  • März 2009
  • Februar 2009
  • November 2008
  • September 2008
  • Mai 2008
  • September 2007
  • Juli 2007
  • Juli 2004
  • März 2003
  • August 2002
  • April 2002
  • Januar 2002
  • Deutsch (de)Deutsch
  • English (en)English
© 2025 sebthom.de | Powered by Minimalist Blog WordPress Theme