Skip to content

allow turning on run tracing from the command line - #623

Closed
terencehonles wants to merge 1 commit into
PyCQA:masterfrom
terencehonles:allow-turning-on-tracing
Closed

allow turning on run tracing from the command line#623
terencehonles wants to merge 1 commit into
PyCQA:masterfrom
terencehonles:allow-turning-on-tracing

Conversation

@terencehonles

Copy link
Copy Markdown
Contributor

This along with some additional tracing output was used to help with #622.

In the additional changes I added the tracing to also print out the stack information when popping the stack. Eventually I added some more context to which stack was being printed and while I shimmed the information in via def popStack(self, node=None) to optionally provide node information for name and file/line context. I was wondering if it would be OK if I were to add a node to each stack created instead of trying to "merge" them via the checker.

For the stack information I printed out if the name was used and if it was available for runtime usage. An example of this would be the following:

fromtypingimportTYPE_CHECKINGifTYPE_CHECKING:
frommoduleimportTypeclassA:
defa(x) ->Type:
passelse:
classA:
defa(x):
passdefb(x) ->Type:
frommoduleimportTypeassertisinstance(x, Type)
returnxclassC:
defc(x) ->Type:
frommoduleimportTypeassertisinstance(x, Type)
returnx
ImportFrom
end ImportFrom
If
Name
end Name
ImportFrom
end ImportFrom
ClassDef
FunctionDef
Name
end Name
end FunctionDef
ClassScope(A):<stdin>:6:5
a:
used: False
runtime: False
end ClassDef
ClassDef
FunctionDef
end FunctionDef
ClassScope(A):<stdin>:10:5
a:
used: False
runtime: True
end ClassDef
end If
FunctionDef
Name
end Name
end FunctionDef
ClassDef
FunctionDef
Name
end Name
end FunctionDef
ClassScope(C):<stdin>:20:1
c:
used: False
runtime: True
end ClassDef
arguments
arg
end arg
end arguments
Pass
end Pass
FunctionScope(a):<stdin>:7:9
x:
used: False
runtime: True
arguments
arg
end arg
end arguments
Pass
end Pass
FunctionScope(a):<stdin>:11:9
x:
used: False
runtime: True
arguments
arg
end arg
end arguments
ImportFrom
end ImportFrom
Assert
Call
Name
end Name
Name
end Name
Name
end Name
end Call
end Assert
Return
Name
end Name
end Return
FunctionScope(b):<stdin>:14:1
Type:
used: True
runtime: True
x:
used: True
runtime: True
arguments
arg
end arg
end arguments
ImportFrom
end ImportFrom
Assert
Call
Name
end Name
Name
end Name
Name
end Name
end Call
end Assert
Return
Name
end Name
end Return
FunctionScope(c):<stdin>:21:5
Type:
used: True
runtime: True
x:
used: True
runtime: True
ModuleScope
A:
used: False
runtime: True
C:
used: False
runtime: True
TYPE_CHECKING:
used: True
runtime: True
Type:
used: True
runtime: False
b:
used: False
runtime: True
isinstance:
used: True
runtime: True

@sigmavirus24sigmavirus24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project doesn't use flags purposefully. Further astpretty does what you're asking very well already

@asottile

Copy link
Copy Markdown
Member

agreed, pyflakes doesn't have any flags currently and there's better tools for visualizing the ast

@terencehonles

terencehonles commented Mar 23, 2021

Copy link
Copy Markdown
ContributorAuthor

agreed, pyflakes doesn't have any flags currently and there's better tools for visualizing the ast

But this is not only about tracing the ast, this is about inspecting pyflake's internal state. Is there a better tool for this currently?

If you think the tracing should be limited to printing scope information I could change that, but I opened this PR in order to figure out if tracing might be helpful and if I should spend any more time on this. (Which currently it looks like no).

@asottile

Copy link
Copy Markdown
Member

Is there a better tool for this currently?

A debugger maybe?

@terencehonles

Copy link
Copy Markdown
ContributorAuthor

Ok, I guess I'm glad I didn't try working on making the tracing more useful.

@terencehonles
terencehonles deleted the allow-turning-on-tracing branch April 12, 2021 23:22
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@terencehonles@asottile@sigmavirus24