Python pseudocode
I want to dynamically annotate returning types for my methods. I want something that looks like this:
class Foo:
def __init__(model: BaseModel):
self.model = model
def find_model(query) -> self.model:
return db.get(query)
And then use it like this:
bar = Foo(model=MyModel) # pass actual class (that inherits from BaseModel), not its instance
obj = bar.find_model('my_query') # here I wanna get MyModel instance
obj. # here I wanna get list of all the available methods and attributes of MyModel instance in Pycharm
Java example
Basically, I want the user to define the returning type. In Java it looks like this:
Foo<Type> obj = new Foo<Type>
And is defined like this:
public class Foo<T> {
private T t;
public Foo(T value) {
this.t = value;
}
}
The question
Is there something similar to this in Python? I only found TypeVar
and ClassVar
, but Pycharm doesn't suggest any methods or attributes when writing code