Steven Barker added the comment:

Thanks for looking at the issue Brett.

I think you're right that your patch has incorrect semantics, since it doesn't 
save the value to the provided namespace if it had to go through the special 
path to find the name. I think my patch got that part right (though I 
definitely missed one PyUnicode_Check).

I've just noticed that our patches may not always do the right thing in all 
error situations. They may return -1 without setting an exception (or perhaps 
passing on a strange one from an internal call) if there's something weird 
going on like `__name__` not existing or not being a string.

I'm attaching a new version of my patch that moves the PyErr_Format call down 
to the later check for `value == NULL`. This handles both the basic case where 
nothing strange goes on but the requested name is not found, and the weird 
cases where unexpected stuff goes wrong. It will replace any errors raised by 
the earlier code with an ImportError. I think an ImportError is the appropriate 
exception for most error cases, but perhaps some internal errors should not be 
overwritten and more complicated error logic is needed.

I also notice that the code in the "import_from" function (from which I 
borrowed heavily for my patch) was changed in one of the 3.5rc patches to have 
new error handling (it raises ImportError more often I think). I don't see an 
obvious way to copy its new error logic to import_all_from, but my C coding 
skills are rather rusty so I could be missing an easy approach.

----------
Added file: http://bugs.python.org/file40649/23447_4.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to