PyCharm type hinting doesn't work with overloaded operators
Question: This was sort of touched on in [this
thread](http://stackoverflow.com/questions/31231541/pycharm-type-error-
message/31367247#31367247), but never resolved.

I have a vector class:

    
    
    class Vector2D(object):
    
        # ...
    
        def __add__(self, other):
            return Vector2D(self.x + other.x, self.y + other.y)
    
        # ...
    
        def __truediv__(self, scalar):
            return Vector2D(self.x / scalar, self.y / scalar)
    

Then, I have a function that is type hinted to accept a Vector2D:

    
    
    def foo(vector):
        """
        :type vector: Vector2D
        """
        print("<{}, {}>".format(vector.x, vector.y))
    

If I try to call `foo` like so, I get a strange warning saying `"Expected type
'Vector2D', got 'int' instead"`:

    
    
    foo((Vector2D(1, 2) + Vector2D(2, 3)) / 2)
    

However, it works fine when I run it, and there is no warning when I
explicitly use the methods of `Vector2d`:

    
    
    foo(Vector2D(1, 2).__add__(Vector2D(2, 3)).__truediv__(2))
    

Please note I am using Python 2.7 but I have `from __future__ import division,
print_function` at the top of all my modules. Any help or advice appreciated.


Answer: Ok, I can't add a comment, because my reputation is too low, but I can create
an answer. Seems legit.

I tried you Code example (using operators) and I didn't get a warning. Even
when I left out `from __future__ import division, print_function`. Also the
right operands (or what are they called?) like `__rmul__` don't produce
warnings. In fact the autocomplete works, too

    
    
    (2 * Vector2D(0, 0))
    

I can press `.` and it shows me the attributes of the `Vector2D` class.

I have PyCharm 4.5.4 Professional.

You can however try to manually specify the return type in the operators:

    
    
    def __add__(self, other):
        """
        :rtype: Vector2D
        """
        return ...
    

You can also try to clear the PyCharm-Cache: `File -> Invalidate
Caches/Restart... -> Invalidate and Restart`

