[issue18750] ''' % [1] doens't fail

2013-08-15 Thread Andrew Svetlov

New submission from Andrew Svetlov:

I think this is a bug.
Can be reproduced on all Pythons (from 2.6 to 3.4a).
Maybe should be fixed for 3.4 only as backward incompatible change.

--
messages: 195263
nosy: asvetlov
priority: normal
severity: normal
status: open
title: ''' % [1] doens't fail

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] ''' % [1] doens't fail

2013-08-15 Thread R. David Murray

R. David Murray added the comment:

What is it that doesn't fail?  The expression in the title is the beginning of 
a triple quoted string with no closing triple quote.

If you mean '' % [1] not falling, it has been that way forever (well, python2.4 
is as far back as I can test), so if it is deemed worth changing it certainly 
should not be backported.

I suspect it is some consequence of the C level similarities between lists and 
dicts, since '' % {anything} is supposed to not produce an error.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] '' % [1] doens't fail

2013-08-15 Thread STINNER Victor

STINNER Victor added the comment:

I don't understand why str % list and str % dict behaves differently than str % 
int:

 'abc' % [1]
'abc'
 'abc' % ([1],)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting
 'abc' % 1
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting
 'abc' % {1:2}
'abc'
 'abc' % ({1:2},)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting

--
nosy: +haypo
title: ''' % [1] doens't fail - '' % [1] doens't fail

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] '' % [1] doens't fail

2013-08-15 Thread R. David Murray

R. David Murray added the comment:

haypo: str % dict is a feature:

   %(a)s % {'a': 1, 'b': 2}
  '1'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] '' % [1] doens't fail

2013-08-15 Thread Andrew Svetlov

Andrew Svetlov added the comment:

For dict it is correct from my perspective.
 % {'a': 'b'}
tries to substitute format specs like %(a)s and does nothing if spec is not 
present.

But list case like
 % [1]
confuse me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] '' % [1] doens't fail

2013-08-15 Thread R. David Murray

R. David Murray added the comment:

Yes, I suspect you are right that that is a bug...and a long standing one :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18750] '' % [1] doens't fail

2013-08-15 Thread Eric V. Smith

Eric V. Smith added the comment:

Objects/unicodeobject.c has this, at line 14316:

if (PyMapping_Check(args)  !PyTuple_Check(args)  !PyUnicode_Check(args))
ctx.dict = args;
else
ctx.dict = NULL;

and later at line 14348:
if (ctx.argidx  ctx.arglen  !ctx.dict) {
PyErr_SetString(PyExc_TypeError,
not all arguments converted during string formatting);
goto onError;
}

Because list now returns true for PyMapping_Check, this code thinks the list is 
a dict and skips the error.

There's some discussion of PyMapping_Check in issue 5945.

--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18750
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com