I am new to Python. I have a function like below which returns a dictionary.
def get_my_class_object(self, input):
return {
"foo": {"test": {}}, // this is hard-coded
"var": "FIRST" // real code computes var using the input
}
I'd like to define a class for the return type so I can enable the type using Pyre. What is the best practice to create a python class for above structure?
I tried below class and changed the function signature to return MyClassObject.
class MyClassObject(NamedTuple):
foo: Dict
var: str
def get_my_class_object(self, input) -> MyClassObject:
// create MyClassObject from input and return the object
But Dict
is not allowed by Pyre as it is too generic. I can't change "foo": {"test": {}}
due to backward compatibility.