[Python-bugs-list] [ python-Bugs-635969 ] No error "not all arguments converted"

noreply@sourceforge.net noreply@sourceforge.net
Tue, 12 Nov 2002 15:01:26 -0800


Bugs item #635969, was opened at 2002-11-09 12:53
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635969&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Martin v. L÷wis (loewis)
Assigned to: Neal Norwitz (nnorwitz)
>Summary: No error "not all arguments converted"

Initial Comment:
The expression 

r'.po$' % "hallo"

used to give an error, but now succeeds and gives the
string '.po'. I think producing the error should be
restored.

----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-12 18:01

Message:
Logged In: YES 
user_id=33168

In order to deal with either the format or the arg being a
string or unicode, I changed the code to check
PyObject_TypeCheck(args, &PyBaseString_Type).  This was
changed in both PyString_Format and PyUnicode_Format.

Checked in as:
 * Objects/unicodeobject.c 2.174
 * Objects/stringobject.c 2.196
 * Lib/test/test_format.py 1.18

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-11-11 05:29

Message:
Logged In: YES 
user_id=6656

You're right.  Please do add a test!  Also note that
unicode's are mappings too.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-10 11:35

Message:
Logged In: YES 
user_id=33168

The problem is that string is a mapping (also changed in
2.166).  The patch below fixes the problem.  Michael, do you
have any problem with this change?  If not, I'll check it in
with a test (unless you beat me to it).

-   if (args->ob_type->tp_as_mapping && !PyTuple_Check(args))
+   if (args->ob_type->tp_as_mapping && !PyTuple_Check(args)
&& !PyString_Check(args))


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-10 10:49

Message:
Logged In: YES 
user_id=33168

Let me try that again:  r'.po$' % ("hallo",)

The line was changed in rev 2.166 by mwh for extended slicing.



----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-10 10:45

Message:
Logged In: YES 
user_id=33168

I'm pretty sure this change (between 2.2.2 and 2.3) in
stringobject.c is the problem:

@@ -3320,7 +3623,7 @@
                arglen = -1;
                argidx = -2;
        }
-       if (args->ob_type->tp_as_mapping)
+       if (args->ob_type->tp_as_mapping &&
!PyTuple_Check(args))
                dict = args;

Now for non-tuples, dict is set.  dict is used later on to
determine if an exception should be set.
This still works, ie produces the exception:  (r'.po$' %
"hallo",)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635969&group_id=5470