PyCharm: specification of the type of variable returned?

advertisements

How do I make PyCharm understand completions for a returned variable?

As per https://www.jetbrains.com/help/pycharm/5.0/type-hinting-in-pycharm.html

I'm asserting the type of a variable, but not getting any completions.

import boto.kinesis
x = boto.kinesis.connect_to_region("us-west-2")
assert isinstance(x, boto.kinesis.layer1.KinesisConnection)

foo = x.    <--- not getting completions here

Python 2,7, PyCharm Community Edition 2016.1.2


This is related to Cannot find reference 'xxx' in __init__.py - Python / Pycharm and the fact that there is no __all__ defined inside the __init__.py inside the boto.kinesis package.

Importing the KinesisConnection directly from boto.kinesis.layer1 made it work for me:

import boto.kinesis
from boto.kinesis.layer1 import KinesisConnection

x = boto.kinesis.connect_to_region("us-west-2")
assert isinstance(x, KinesisConnection)


You can also import it and add a type hint into the comments:

import boto.kinesis
from boto.kinesis.layer1 import KinesisConnection

x = boto.kinesis.connect_to_region("us-west-2")  # type: KinesisConnection