F
F
Fedor2021-12-03 23:41:31
Python
Fedor, 2021-12-03 23:41:31

How to determine the position of a method in a call chain?

Greetings!
- - -
I need an object for call tracing.

class MyTracerClass:
    def __init__(self):
        self._trace = []

    def __getattr__(self, item):
        # как вот здесь определить, что дальше ничего не вызывается?
        self._trace.append(item)
        return self


tracer = MyTracerClass()
tracer.aaa.bbb.xxx

How to understand from inside the tracer object that after the methods / parameters aaa, bbb something was called, but xxx was the last one in the chain? Not calling any more additional methods after xxx .
The names of methods / parameters and their number can be different, it is important for me to understand how to determine the last method / parameter in a line.
- - -
PS: Maybe you can see from the object the line of code in which this object is accessed?
Thanks:)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question