Intellisense not identifying certain types

Feb 15, 2013 at 3:57 AM
I'm using MS PTVS 1.5..51026.0 in VS 2010.

If I type the following (partial) code in a file, intellisense will recognize in_file as being a file, and offer a list of methods including readlines(), but does not have any type information for line.
in_file = open("foo.txt", "r")
for line in in_file.readlines():
    line.
I would have expected it to be able to work out that line is a string.
Is this a bug/deficiency in intellisense?
Is there anything I can do to help it identify line as a string?
Coordinator
Feb 15, 2013 at 4:32 PM
This is a deficiency, but it should be addressed in our next release, since I've just finished rewriting a large part of how we analyse code. At the moment, we know that readlines() returns a list, but we don't know what is in that list.

The easiest way to force a certain type is to assign it:
in_file = open("foo.txt", "r")
line = ""
for line in in_file.readlines():
    line.
The extra assignment could be if False: line = "" if you don't want to actually execute it.

We also handle the following pattern:
in_file = open("foo.txt", "r")
for line in in_file.readlines():
    assert isinstance(line, str)
    line.
This has the added benefit of removing any other types from line. It's not always reliable in the current version, but I've fixed it for the next. (We'll have a preview release soon, which is when this sort of feedback is going to be really important to us.)
Feb 19, 2013 at 11:49 AM
Cool. Thanks for the reply and tips.