     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Jython" href="https://sebthom.de/de/category/it/development/jython/feed/" />
{"id":140,"date":"2010-02-20T00:29:00","date_gmt":"2010-02-19T23:29:00","guid":{"rendered":"http:\/\/sebthom.de\/?p=140"},"modified":"2012-12-18T19:47:07","modified_gmt":"2012-12-18T18:47:07","slug":"leveraging-pydevs-auto-completion-indirectly-created-objects","status":"publish","type":"post","link":"https:\/\/sebthom.de\/de\/140-leveraging-pydevs-auto-completion-indirectly-created-objects\/","title":{"rendered":"Leveraging PyDev&#8217;s auto-completion for indirectly created objects"},"content":{"rendered":"<p>This is just a quick tip how to enable auto completion in <a href=\"http:\/\/pydev.org\">PyDev<\/a> for indirectly created objects. <\/p>\n<p>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. <\/p>\n<p>For example, when you first type &#8230;<\/p>\n<pre name=\"code\" class=\"python\">mybook = Book()<\/pre>\n<p>&#8230; and in the next line you enter &#8230;<\/p>\n<pre name=\"code\" class=\"python\">mybook.<\/pre>\n<p>&#8230; PyDev will dutifully present you the statically declared features for the Book class in a popup.<\/p>\n<p>If you however get that Book instance as the result of another method, e.g. &#8230;<\/p>\n<pre name=\"code\" class=\"python\">mybook = bookstore.findBook(\"foobar\")<\/pre>\n<p>&#8230; PyDev currently seems to be helpless. <\/p>\n<p>Because of Python&#8217;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 <a href=\"http:\/\/epydoc.sourceforge.net\/manual-epytext.html\">PyDoc<\/a> annotations (which you can add to the findBook&#8217;s method declaration) but currently it just does not.<\/p>\n<p>To still have auto-completion you have two options:<\/p>\n<ol>\n<li> Temporarily instantiate a Book object in the code.\n<pre name=\"code\" class=\"python\">\r\nmybook = Book()\r\nmybook = bookstore.findBook(\"foobar\")\r\nmybook. #--> now you have auto completion\r\n<\/pre>\n<p>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.<\/p>\n<li> Use an assertion to ensure that the mybook variable contains an object of type Book\n<pre name=\"code\" class=\"python\">\r\nmybook = bookstore.findBook(\"foobar\")\r\nassert isinstance(mybook, Book)\r\nmybook. #--> now you have auto completion\r\n<\/pre>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63],"tags":[105,76,78,65,77],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-jython","tag-jython","tag-pydev","tag-pydoc","tag-python","tag-rtype"],"_links":{"self":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":0,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}