pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.4k stars 710 forks source link

Question: purpose of check-ast ? #1029

Closed sasa-buklijas closed 8 months ago

sasa-buklijas commented 8 months ago

By reading https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#check-ast, my understanding is that it check if file is valid python.

I have done test with following file:

def main():
    print('Hello, World !!!')

if __name__ == "__main__":
    main()

sdfsdfsdf()

And result is:

$ python main.py 
Hello, World !!!
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    sdfsdfsdf()
NameError: name 'sdfsdfsdf' is not defined

I understand that there are better tool for checking python files/syntax, but just like to understand what is idea behind it ?

asottile commented 8 months ago

your file contains no syntax errors. notice how your error is NameError and not SyntaxError

try putting a $ in your source somewhere (as it's not a valid token in python yet) and you'll see a SyntaxError

sasa-buklijas commented 8 months ago

your file contains no syntax errors. notice how your error is NameError and not SyntaxError

try putting a $ in your source somewhere (as it's not a valid token in python yet) and you'll see a SyntaxError

Understand that, but still wondering what is what is use/idea of check-ast ? Do not see use in production or am I missing something ?

asottile commented 8 months ago

have you tried searching the issue tracker or the git history for the answer?

sasa-buklijas commented 8 months ago

honestly not, only quick google search, would expect link in readme.

asottile commented 8 months ago

ok if you're not going to put in basic effort to answer your questions I hope you can see why I am not going to put in basic effort to help you

sasa-buklijas commented 8 months ago

All I am saying if there is addition info regarding check-ast I see not harm in providing it in readme, as text or link.

Do not thing that I am the only one when reads "Simply check whether files parse as valid python." assumes that this means that it can be used for fast check of program.

All the best.

asottile commented 8 months ago

Do not thing that I am the only one when reads "Simply check whether files parse as valid python." assumes that this means that it can be used for fast check of program.

your read is completely correct but you don't know what a syntax error is and it's not the readme's job to teach you a basic concept of programming

or it could but the readme would become a cookbook sized document of mostly useless information