Wing also "sees" code nested in 'if 0:' blocks so you don't need the code to run even in __debug__ mode.
My code is littered with stuff like this:
if 0: assert isinstance(foo, MyClass) #for Wing
This code is never run and is explicitly for Wing autocompletion.
Russ
-----Original Message-----
From: wingide-users-bounces at wingware.com [mailto:wingide-users-bounces at wingware.com]On Behalf Of Vania Smrkovski
Sent: Sunday, September 03, 2006 9:28 AM
To: Toni Ruža
Cc: wingide-users at wingware.com
Subject: Re: [wingide-users] An idea for better auto-completion
Wing already does this for you.
If you use assert(isinstance(variable, type)), Wing will pick up on the assert, and knowing that the assert will not allow processing to continue past this point unless the assertion is met, it will presume everthing following will treat that variable as that type and give you appropriate behaviors.
There is a section in the documentation which, embarrassingly, I also overlooked the first time, that also suggests that you can minimize problems with circular imports by wrapping this code in if __debug__: blocks. If, for instance, your module does not NEED to know that your variable type is an instance of wx.TreeCtrl because your currently edited page in the module doesn't import wx.anything, but you want to use code-completion to access barely-remembered wx.TreeCtrl methods and variables, you can use
if __debug__:
import wx
assert(isinstance(tablesTree, wx.TreeCtrl))
In this case, if I understand the specifics correctly, Wing will know to find the TreeCtrl object in wx and provide you with appropriate assistance, and of course when you run the app, that import will be attempted, if it hasn't already happened. But when you run your Python with the no debug flag -) and all if __debug__ blocks and assert() statements will be overlooked in the compile.
On 9/3/06, Toni Ruža < gmr.gaf at gmail.com> wrote:
It often happens that Wing cannot tell the type of a certain variable
and is unable to provide auto-completion (for example for a function
argument). In almost all of those situations the programmer knows the
type of that variable so it would make sense to help Wing out by
somehow letting it know about it, maybe in some kind of specially
formatted comment.
What do you think about this? Should we press wingware to implement
something like it? Or am I missing something? Does this already exists
is some form?
I often use a little trick for this but I don't like it. For example if I have:
def foo(bar):
...
And I know "bar" will be a "SomeClass" instance, i temporarily put a
"bar = SomeClass()" in the first line of the function and the
auto-completion works fine.
_________________________________________________
Wing IDE users list
http://wingware.com/lists/wingide
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20060905/94dfac81/attachment.html