Old question, but there are ways to do this, e.g. by inspecting frames like LightningCLI does https://github.com/Lightning-AI/pytorch-lightning/blob/be608fa355b835b9b0727df2f5476f0a1d90bc59/src/lightning/pytorch/utilities/parsing.py#L176
However, the ways above are definitely simpler and more robust.