Bug 430991

Summary: Miss handling of errors by error handler in python
Product: [Fedora] Fedora Reporter: Aaron Konstam <akonstam>
Component: pythonAssignee: James Antill <james.antill>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 7CC: ivazqueznet, james.antill, katzj
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-01-30 23:10:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Show how to catch a TypeError within a function none

Description Aaron Konstam 2008-01-30 23:06:45 UTC
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 23:10:32 UTC
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-31 00:40:05 UTC
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 15:42:18 UTC
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.