dsa-ou / allowed

Check if a program only uses a subset of the Python language.
https://dsa-ou.github.io/allowed/
BSD 3-Clause "New" or "Revised" License
10 stars 6 forks source link

Use stderr more consistently? #63

Open mwermelinger opened 6 months ago

mwermelinger commented 6 months ago

Currently, any errors raised by argparse (like calling allowed -b file.py) go to stderr, everything else goes to stdout, including due to sys.exit().

What is the approach used by other linters? What do we gain by separating stdout and stderr?

densnow commented 6 months ago

RE exit codes, I like the way ruff does things (see ruff exit codes):

The numbers used here are irrelevant (apart from the following of some unix conventions), I like this is because it is consistent and well documented. It makes it easier to integrate with other tools when scripting or using it in pipelines.

It's the same justification for clearly separating stderr and stdout, as was mentioned in #62 when commands are part of pipelines then you don't want error messages mixed in with the data. Of course the majority of use cases for allowed will not involve scripts and pipelines etc, but IMHO it can't do any harm to make integration with other tools easier.

As mentioned, there are a couple of tricky cases in allowed's output that would need consideration, but I think consistency is the key. If syntax errors for .py files go to stderr then so should syntax errors for cells in .ipynb. Abnormal termination and warnings also go to stderr. Anything which is considered normal output for the program (i.e reported violations of the python subset) goes to stdout. A logging output (as per #62) could be considered normal output, and, since it will have an option to switch off, can go to stdout.

mwermelinger commented 6 months ago

While in principle I agree with you, I think this needs looking into how ruff, pylint and others separate stdout and stderr. Since there are higher priority issues to work on for 24J, I'm not going to work on this for now.