On Tuesday, June 11, 2013 3:40:12 PM UTC+4, Jun T. wrote:
> I can't reproduce the error, but
> 
> On 2013/06/11, at 1:46, Bram Moolenaar <[email protected]> wrote:
> > The following differences ones are similar.
> 
> so the following simpler test (line 536 of test86.ok) also fails similarly?
> 
> >>> Testing *Iter* using d["a"] = %s
> d["a"] = FailingIter():(<type 'exceptions.TypeError'>, TypeError('unable to 
> convert to vim structure',))
> 
> The code tested here is essentially like the following:
> 
> :py d = vim.bindeval("{}")
> :py <<EOF
> class FailingIter(object):    # has __iter__() but no next()
>     def __iter__(self):
>         raise NotImplementedError
> obj = FailingIter()   # obj is introduced for the discussion below
> d["a"] = obj
> EOF
> 
> 'TypeError: unable to convert to vim structure' may mean:
> The object obj is not an iterator (nor any other object type I know),
> so I can't convert it into data structure which vim knows.
> 
> The other error, NotImplementedError, may mean:
> obj looked like an iterator, so I tried to iterate over it but failed.
> 
> Since it is obvious that FailingIter() is not an iterator, I think
> the former behavior is better; calling __iter__() can cause more
> serious problem than just NotImplementedError in real (not test) code.
> If we know that calling it is useless (since there is no next() method
> anyway), it would be better not to call it, I suppose.

Converted object does not have to be an iterator *itself*, it may be 
*conversible* to the iterator. Built-in str() also does not have .next() 
method, but you can do `for character in "abc"`. And there is no other 
(standard) way in python C API to check whether object is an iterator then 
trying to use PyObject_GetIter (you can e.g. check for obj->ob_type->tp_iter, 
but I can’t say whether or not this is going to always work properly. In any 
case this method is not supported).

Thus everywhere I expect the iterator, I just call PyObject_GetIter in place of 
doing any type checks. But where I do not expect certain types (i.e. in 
ConvertFromPy{Object,Mapping}) PyObject_GetIter is not used. Thus after this 
discussion I find original TypeError be expected: in this code 
ConvertFromPyObject is used thus it should not pass type checks.

You are right for your and Bram example: there should be TypeError. You would 
not be right if you have shown some of the commented out tests.

I can also now say that it is clear that something did break.

Tests for which FailingIter was written (where it should return 
NotImplementedError: d.update(%s), vim.List(%s), l.extend(%s) and so on) all 
appear to be commented out for python2.

> BTW, in test86.in, there are several uncommented (disabled) tests like
> (line 933, 973, ...)
> 
> #iter_test('sys.stdout.writelines(%s)')
> #iter_test('d.update(%s)')
> 
> Are these related to the current problem?

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui