[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Julian

New submission from Julian julian+python@grayvines.com:

Attached is just a failing test case (just `print({}.format_map(12))`), 
haven't been able to decipher the chain of calls in the unicodeobject.c code 
yet to see where the best place to put the fix would be (inside do_format_map 
before the pass back upwards maybe?).

Assuming this should be a TypeError obviously, soon as I can figure out where 
to put the fix I'll update the patch.

--
components: Interpreter Core
files: format_map_err.patch
keywords: patch
messages: 140528
nosy: Julian
priority: normal
severity: normal
status: open
title: str.format_map raises a SystemError for non-mapping
versions: Python 3.2, Python 3.3
Added file: http://bugs.python.org/file22681/format_map_err.patch

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +eric.smith

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Eric V. Smith

Changes by Eric V. Smith e...@trueblade.com:


--
assignee:  - eric.smith

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Eric V. Smith

Eric V. Smith e...@trueblade.com added the comment:

If you want to look at this, I think there's a missing check for args being 
non-null in string_format.h, line 515.

I'd have to think to see if there are other possible failure scenarios.

Thanks for the report.

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Eric V. Smith

Eric V. Smith e...@trueblade.com added the comment:

Actually that's probably not the place to catch it. Let me look at it closer. 
Of course, patches welcome!

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Julian

Julian julian+python@grayvines.com added the comment:

Yeah, I saw the line you suggested and didn't think that was it.

To expand on this, perhaps {foo}.format(12) should raise a TypeError as well? 
I'd expect that more than the current behavior which is a KeyError. That 
KeyError is getting raised in get_field_object, which is where the fix needs to 
be, or at least needs to be changed, I'm just trying not to duplicate code.

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Julian

Julian julian+python@grayvines.com added the comment:

Sorry for the double post, meant to say, in line 506.

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Eric V. Smith

Eric V. Smith e...@trueblade.com added the comment:

I think KeyError for {foo}.format(12) is correct. It's looking up foo in 
the empty dict of **kwargs.

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Julian

Julian julian+python@grayvines.com added the comment:

Fair enough. I suppose I take .format_map to mean, here is a mapping, call 
__getitem__ on it for each of the keys inside the format string, to which 
calling 12[foo] would get me a TypeError.

I suppose I see both as appropriate, but the fact that it's implemented by 
passing the mapping as kwargs seemed less relevant. Less concerned about that 
part though I guess.

--

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



[issue12579] str.format_map raises a SystemError for non-mapping

2011-07-17 Thread Eric V. Smith

Eric V. Smith e...@trueblade.com added the comment:

I think the issue is that it should be an error in any string used for 
format_map() to have a positional argument. So the right thing to do is detect 
this case in get_field_object (index != -1 and args is NULL). So I think a new 
test near line 515 really is the right thing to do. With a good comment 
explaining what's going on.

I'm pretty sure the only case where args is NULL is when used with 
format_map(), but that needs to be verified.

--

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