-
Notifications
You must be signed in to change notification settings - Fork 52
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
Promote warnings to errors? #114
Comments
On the face of it, it feels like a big deal to decide that all warnings are now exceptions. Why do you suggest this, Albert? (Beyond that it's easy. I'm sure there's plenty I'm not aware of.) |
I'll admit that my thinking is probably stuck in the normal world, and I'm not really thinking through the implications of warnings in restricted python. (What would be the primary source of warnings? Syntax things from core python? Deprecations with newer python versions? How often are we even going to allow code base changes? We're not sure if/when python 3 is going to happen, I suppose.... Thinking aloud.) Options:
As for option 2: Since you say that that single line change would raise all warnings as exceptions, and since you imply that that requires no retooling of safe.py, what if we do that and have a wrapper basically |
I'm suggesting this change so as to minimize the surprise that the user encounters when the Repy runtime (as opposed to Repy user code) raises warnings, given the rare but confusing Sources of warnings: At the moment, we have one single suppressed warning from the Repy runtime (importing Unlike other libraries and projects ( Overall, warnings that are raised from the runtime are both seldom, and usually right. Tongue-in-cheekly, what were the 10 last warnings you saw from Repy or the Python standard libs, and over what timespan did you see them? Me, I'm at two overall, over 6 years. More importantly, warnings in our case indicate that user code does something that's very likely unintended anyway. Replying to your points,
So for the runtime side of things where warnings probably arise inadvertently, I think my patch makes sense. For the user code side where own warnings could be defined and used, I don't think it makes a difference. |
You're right on all counts (EDIT: i.e. on your responses to 1, 2, and 3), I think. The catch-all-warnings-raised-as-exceptions thing was a backward thought. 😅 I still don't love it on principle, but if as you say it's that exceptionally rare... OK. (: I'll try to keep it in the back of my mind in case some parallel thing needs to be added to safe.py later. I'll write a unit test for this. I had a thought about a full integration/regression test for things like this - say, picking some canonical Seattle experiment and having it run and confirming that output fits... but existing unit tests probably suffice. In any case, before we get to something like that, we should probably fix all the unit tests. (: |
Others can compare the non-informative result one would get from a dylink-run test currently (pre-commit), above, with the result when your commit is included, below. It's noisy, but at least it shows the actual warning at the end there.
|
Above, you say:
(Without the fix commit,) I ran such a snippet on a vessel via seash and the warning appears in the log file, just as an error would. Here's the example, a script named example.r2py:
And then I do this in seash:
What am I missing? |
Confirmed with Albert that the warnings actually appear in the log on VMs - so that's not a problem. The issue when dylink is used, though, remains that warnings are both fatal and incomprehensible without Albert's patch. So we should still go through with it. I'm wrestling with another possible workaround first. |
(Note: The mechanics of the problem were first discussed under the tangentially related #69.)
There are a few code constructs that can raise
Warning
s (see Python docs), which can cause trouble in nestedVirtualNamespace
s (as used bydylink
for example).For example, consider the snippet
This does not raise an
AssertionError
, becauseassert
is a keyword (not a function), so the parenthesized expression evaluates as atuple
(rather than as arguments), which is truthy. This generatesSyntaxWarning: assertion is always true, perhaps remove parentheses?
onstderr
as a notification about this problem, but the program will continue to run.If you run RepyV2 from the command line, you will see the
SyntaxWarning
. If you run the above snippet on a vessel, you won't see the message. This might or might not be a problem for you.However, if you run the snippet inside of a
VirtualNamespace
, or in a program that usesdylink
, theSyntaxWarning
causes this weird traceback, courtesy of Python'swarning
library that gets invoked when the nestedVirtualNamespace
is checked for safety and found to contain the potential syntax problem (see #69):We could probably stash the unsafe calls required by
warnings
insafe.py
somehow, as we do with a couple of others (likegetattr
), and through this enable the behavior ofSyntaxWarning
(and other warnings) as in the non-dylink
ed / non-VirtualNamespace
case.I would personally prefer to promote warnings to errors instead, so that proper exceptions are raised for every warning. This requires a simple one-line patch,
and does two things: It stops the program, and outputs the warning message in a visible manner, regardless of whether you can see
stderr
:The text was updated successfully, but these errors were encountered: