예제 #1
0
        /// <summary>
        /// Move to the next item in this iterable
        /// </summary>
        /// <returns>True if moving was successfull</returns>
        public bool MoveNext()
        {
            PythonTypeOps.TryGetOperator(DefaultContext.Default, _baseObject, "__next__", out object nextMethod);

            if (nextMethod == null)
            {
                throw PythonOps.TypeErrorForNotAnIterator(_baseObject);
            }

            try {
                _current = DefaultContext.Default.LanguageContext.CallLightEh(DefaultContext.Default, nextMethod);
                Exception lightEh = LightExceptions.GetLightException(_current);
                if (lightEh != null)
                {
                    if (lightEh is StopIterationException)
                    {
                        return(false);
                    }

                    throw lightEh;
                }
                return(true);
            } catch (StopIterationException) {
                return(false);
            }
        }