Classes

  1. class MyClass(object):
  2. # For instance methods, omit type for "self"
  3. def my_method(self, num, str1):
  4. # type: (int, str) -> str
  5. return num * str1
  6.  
  7. # The "__init__" method doesn't return anything, so it gets return
  8. # type "None" just like any other method that doesn't return anything
  9. def __init__(self):
  10. # type: () -> None
  11. pass
  12.  
  13. # User-defined classes are valid as types in annotations
  14. x = MyClass() # type: MyClass