Inspect object to get the entire composite object it belongs to

37 Views Asked by At

Say I have nested pydantic.BaseModel(s) (but my question is not class specific). At one point, I am calling a method by providing conf.compta.fec as argument. conf is a composite BaseModel, attributes of which are also BaseModels (at least compta and fec)

PathAssembler.generate_abfss_uri("SomeTable", conf.compta.fec, "container")

From the stand point of the function, I would like to be able to identify the entire conf.compta.fec chain by inspecting model. In other words, I would like to get all the classes model is recursively an attribute of

class PathAssembler:
    @classmethod
    def generate_abfss_uri(cls, table_name: str, model: BaseModel, container_name: str, delta=True):
        # HERE: how to get the classes `model` is the composite of ?
        return f"abfss://{container_name}//{table_name}{'.delta' if delta else ''}"

How can I achieve this? Could `inspect be of any help?

0

There are 0 best solutions below