Feature or enhancement
This report actually suggest removing a feature.
When trying to add information about warnings in friendly-traceback, I found out that cPython emits SyntaxWarnings for code that triggers exceptions. In some cases, the warnings include hints of dubious value. Ignoring the hint, the message tacked on to the SyntaxWarning is identical to that provided by the exception that is raised.
Here are two examples.
Python 3.10.2 ... on win32
>>> import warnings
>>> warnings.simplefilter("always")
>>> 1[2]
<stdin>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not subscriptable
>>> [1, 2, 3]()
<stdin>:1: SyntaxWarning: 'list' object is not callable; perhaps you missed a comma?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
I am wondering about the value of emitting such warnings, and if this does result in reduced efficiency.
I realize that, if one uses compile(statement, filename, "single"), a SyntaxWarning will be shown without triggering an exception, but even then I fail to see the usefulness of emitting such warnings, and wonder about the additional code complexity required to provide this information, which is likely not visible by the vast majority of users who do not enable warnings.
Feature or enhancement
This report actually suggest removing a feature.
When trying to add information about warnings in friendly-traceback, I found out that cPython emits
SyntaxWarnings for code that triggers exceptions. In some cases, the warnings include hints of dubious value. Ignoring the hint, the message tacked on to theSyntaxWarningis identical to that provided by the exception that is raised.Here are two examples.
I am wondering about the value of emitting such warnings, and if this does result in reduced efficiency.
I realize that, if one uses
compile(statement, filename, "single"), aSyntaxWarningwill be shown without triggering an exception, but even then I fail to see the usefulness of emitting such warnings, and wonder about the additional code complexity required to provide this information, which is likely not visible by the vast majority of users who do not enable warnings.