Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show object attributes, not just local variables #7

Closed
rtphokie opened this issue Apr 22, 2019 · 3 comments
Closed

show object attributes, not just local variables #7

rtphokie opened this issue Apr 22, 2019 · 3 comments

Comments

@rtphokie
Copy link

rtphokie commented Apr 22, 2019

Consider this code:

class Foo():
    
    def __init__(self):
        self.a = 1
        self.b = 2
        self.c = None
        
    @pysnooper.snoop()
    def myfunc(self):
        localvar = 5
        localvar += 1
        self.c = self.b + self.a

pysnooper's output when calling myfunc:

Starting var:.. self = <snooptest.Foo instance at 0x1052c5b90>
08:50:38.552499 call        16     @pysnooper.snoop()
08:50:38.553309 line        18         localvar = 5
New var:....... localvar = 5
08:50:38.553382 line        19         localvar += 1
Modified var:.. localvar = 6
08:50:38.553457 line        20         self.c = self.b + self.a
08:50:38.553560 return      20         self.c = self.b + self.a

The values of self.a, self.b, and self.c are not shown by pysnooper but are the primary purpose of this method. parameters on self should also be shown as starting values in methods decorated by pysnooper

@cool-RR
Copy link
Owner

cool-RR commented Apr 22, 2019 via email

@rtphokie
Copy link
Author

That's what the variables argument is for. Also, if the classes' repr uses these attributes, they'll show up even if they aren't included in variables .

On Mon, Apr 22, 2019, 16:23 Tony Rice @.***> wrote: Consider this code: class Foo(): def init(self): self.a = 1 self.b = 2 self.c = None @pysnooper.snoop() def myfunc(self): localvar = 5 localvar += 1 self.c = self.b + self.a pysnooper's output when calling myfunc: Starting var:.. self = <snooptest.Foo instance at 0x1052c5b90> 08:50:38.552499 call 16 @pysnooper.snoop() 08:50:38.553309 line 18 localvar = 5 New var:....... localvar = 5 08:50:38.553382 line 19 localvar += 1 Modified var:.. localvar = 6 08:50:38.553457 line 20 self.c = self.b + self.a 08:50:38.553560 return 20 self.c = self.b + self.a The values of self.a, self.b, and self.c are not shown by pysnooper but are the primary purpose of this method. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#7>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAN3SRLATTZU5LTBC6HLIDPRW343ANCNFSM4HHPVXXQ .

But doesn't that defeat the purpose of this easy to use debugging decorator? Having to specify which variables you want to be instrumented?

@cool-RR
Copy link
Owner

cool-RR commented Apr 22, 2019 via email

@cool-RR cool-RR closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants