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

allow turning on run tracing from the command line #623

Closed

Conversation

terencehonles
Copy link
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:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from module import Type

    class A:
        def a(x) -> Type:
            pass
else:
    class A:
        def a(x):
            pass

def b(x) -> Type:
    from module import Type

    assert isinstance(x, Type)
    return x

class C:
    def c(x) -> Type:
        from module import Type

        assert isinstance(x, Type)
        return x
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

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

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
Member

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

@asottile asottile closed this Mar 23, 2021
@terencehonles
Copy link
Contributor Author

terencehonles commented Mar 23, 2021

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
Member

Is there a better tool for this currently?

A debugger maybe?

@terencehonles
Copy link
Contributor Author

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 free to 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