There is a ->
, or dash-greater-than symbol at the end of a python method, and I'm not sure what it means. One might call it an arrow as well.
Here is the example:
@property
def get_foo(self) -> Foo:
return self._foo
where self._foo
is an instance of Foo.
My guess is that it is some kind of static type declaration, to tell the interpreter that self._foo
is of type Foo. But when I tested this, if self._foo
is not an instance of Foo, nothing unusual happens. Also, if self._foo
is of a type other than Foo, let's say it was an int
, then type(SomeClass.get_foo())
returns int
. So, what's the point of -> Foo
?
This concept is hard to lookup because it is a symbol without a common name, and the term "arrow" is misleading.