This project has moved and is read-only. For the latest updates, please go here.

Question on code completion

Dec 11, 2012 at 3:30 PM

I am new to python.

I have this code:

import logging
logger = logging.getLogger('snakeguice')

and when I start typing the following 'logger.'    I do not get code completion;  I get a list of __doc__, __hash__, etc but noting else.  When I hover over logger I get 'NoneType'.

I am assuming this is because it does not know the returning datatype of logging.getlogger().  Is there any way to tell the autocomplete what the datatype is, so that autocomple will work on that datatype?

Dec 11, 2012 at 4:43 PM

I thought we had added support such that "assert isinstance(logger, logging.Logger)" would update the analysis information, but apparently not.

With the current version, you can do this:

import logging
logger = logging.getLogger('snakeguice')

if False:
    logger = logging.Logger()

which will add Logger as a possible type for logger, though you still may not see any completions until you disable "Member completion displays intersection of members" in Tools->Options->Text Editor->Python->Advanced (IMO this option should be disabled by default...)

As for why we don't get the type right in the first place, I'm not entirely sure. We know the types returned from getLogger (there are four possibilities, so even if this did work properly it still may not be that helpful) but they aren't being attached to getLogger itself. I'm already working on this area of our code, so I'll see if I can figure out what's going on.