python mixin return type

Hi,

I wonder if it's possible to specify the return type of a function in the superclass so pycharm will recognize the correct return type.

class CRUDMixin(object):
    id = db.Column(db.Integer, primary_key=True)

    @classmethod
    def get_by_id(cls, id) -> object:
        if any((isinstance(id, str) and id.isdigit(), isinstance(id, (int, float))), ):
            return cls.query.get(int(id))
        return None

class User(CRUDMixin, Model):
    ...
prettyPrint();

Is there a way to set up the crudmixin class in a way that if I use User.get_by_id() pycharm automaticly recognizes that it will return a User object.. like "self" or "cls" or something like that ?

Bastian
1 comment
Comment actions Permalink
Just wonder of the same thing in type hinting system of PyCharm (Python plugin for IDEA). Also, what do "generics" stand for in PyCharm type hinting documentation:
  • T # Generic type (T-Z are reserved for generics)
  • T <= Foo # Generic type with upper bound Foo
  • Foo[T] # Foo parameterized with T
0

Please sign in to leave a comment.