Bug 430991 - Miss handling of errors by error handler in python
Miss handling of errors by error handler in python
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: python (Show other bugs)
7
All Linux
low Severity low
: ---
: ---
Assigned To: James Antill
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-30 18:06 EST by Aaron Konstam
Modified: 2008-01-31 10:42 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-01-30 18:10:32 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Show how to catch a TypeError within a function (329 bytes, text/plain)
2008-01-30 19:40 EST, James Antill
no flags Details

  None (edit)
Description Aaron Konstam 2008-01-30 18:06:45 EST
Description of problem:
At the risk of starting an argument I find a bug in the functioning of the
exception handling system try-except in python. An illustration will illlustrate
the problem I see. Take the function:
 def plus(a,b):
    try:
               return(a+b)
     except TypeError:
               return None
If I execute it as: plus(3,)
the following is returned:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: plus() takes exactly 2 arguments (1 given)


Now this is explained by some people by saying the error in arguments is
found before the plus is executed so the TypeError is not found within the plus
clause. I have taught interpreter writing and I know that the check of the
arguments is done before the plus is executed in machine code. However, the
exception handler is supposed to work on the python source level. A TypeError is
generated on the python line plus(3,) and it should be caught.
f8 has the samme problem.

Version-Release number of selected component (if applicable):

python-2.5-15.fc7
How reproducible:

every time
Steps to Reproduce:
1.execute:  plus(3,)
2.
3.
  
Actual results:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: plus() takes exactly 2 arguments (1 given)


Expected results:

no output
Additional info:
I assume this would happen with and error thrown.
Comment 1 Ignacio Vazquez-Abrams 2008-01-30 18:10:32 EST
1) The error is generated outside of the function.
2) The error is generated outside of the try block inside the function.
Comment 2 James Antill 2008-01-30 19:40:05 EST
Created attachment 293526 [details]
Show how to catch a TypeError within a function

 I'm not sure why you posted this here ... did you really expect Fedora to
alter the python language?

 I'd also suggest that you go read the python language tutorials etc. quite a
bit more, I've attached a "solution" to your problem written using normal
python.
Comment 3 Aaron Konstam 2008-01-31 10:42:18 EST
Well I will drop this buut I don't agree with the analysis in comment #1 above:
Thhe error is generated when the function is taken by the interpreter to
execute. I f we don't know what function we are executing we don't know how many
arguments we are executing.
The construct is:
try
   <execution block>
except TypeError
    action

It is a python source construct. Its defineition is that is an error occurs in
the <execution block> thenn the action will occur. This error is obviiously
genrated in the try block and should be caught. The statemennt in 2) aboive is
obviously fallacious from a python source perspective.

I will drop this because it is bug is obviously part of the original python
implimentation and no one wants to admit they were wrong all these years.

I responded to comment #2 directly and commented on his demaning tone which he
could get rid of. I own the Python Language Reference Manual Release 2.3 and I
would claim the behavior of the python interpreter in Fedora is contrary to the
decriptiion of its operation in that manual.

Note You need to log in before you can comment on or make changes to this bug.