[wingide-users] Hacking .pi files for better code completion

Wingware Support support at wingware.com
Wed May 14 07:01:11 MDT 2008


Tim Mitchell wrote:
> I have some enumerated types (using my own variant on the enum package), 
> for example:
> 
> TIME_UNITS = enum("Undefined", "Seconds", "Minutes", "Hours", "Days", 
> "Years")
> LENGTH_UNITS = enum("Undefined", "Feet", "Metres", "Centimetres")
> 
> The enum function creates a class instance with attributes for each 
> value. e.g.
> TIME_UNITS.Seconds
> 
> Unfortunately there is no way for any source analyser to know this 
> (without running the code).
> Is there a way I can hack the .pi file to provide code completion for 
> these enumerated types? There will be alot of them (eventually).
> I was thinking of something along the lines of running the file with the 
> enumerated types and generating a pi file from the module dict.  (this 
> would work because the attributes will then exist on the objects).

Wing doesn't read the .pi files when there's already a .py file present,
so that probably won't help.  Using isinstance would work if you can
import what you would essentially have put into the .pi file.  It may
not be the greatest solution since you'ld have an isinstance under
each enum() call.

One idea would be to change from runtime creation of the classes to a
preprocessor of some type, so that your code imports the output of
that processing rather than the above source.

Note BTW that the auto-completion in the Debug Probe and Python Shell
would correctly handle this case since they source their data from
the live runtime.

-- 

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com



More information about the wingide-users mailing list