Skip to content

Conversation

@Zeroto521
Copy link
Contributor

call next to a dict won't work.

In [14]: from pyscipopt import Model

In [15]: x = m.addVar()

In [16]: next(x)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
Cell In[16], line 1
----> 1 next(x)

StopIteration:

In [17]: next(x+1)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
Cell In[17], line 1
----> 1 next(x+1)

StopIteration:

In [18]: next(abs(x))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[18], line 1
----> 1 next(abs(x))

TypeError: 'pyscipopt.scip.UnaryExpr' object is not an iterator
In [19]: next({1:1, 2:2})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[19], line 1
----> 1 next({1:1, 2:2})

TypeError: 'dict' object is not an iterator
In [20]: next(iter({1:1, 2:2}))
Out[20]: 1

In [20]: next(iter({1:1, 2:2}))
Out[20]: 1

The __next__ method was removed from the Expr class, leaving only __iter__ for iteration. This simplifies the class and relies on the iterator protocol of self.terms.
Copilot AI review requested due to automatic review settings January 22, 2026 07:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the Expr class by removing an incorrectly implemented __next__ method. The class is designed to be an iterable (like a Python dict) rather than an iterator.

Changes:

  • Removed the broken __next__ method from the Expr class that was attempting to call next() on a dict object

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Zeroto521 and others added 2 commits January 22, 2026 15:06
The __next__ method was removed from the Expr class in the type stub file, likely because Expr is not intended to be an iterator. This change improves the accuracy of the type hints.
@Joao-Dionisio Joao-Dionisio self-requested a review January 22, 2026 11:39
@Joao-Dionisio Joao-Dionisio enabled auto-merge (squash) January 22, 2026 11:40
@Joao-Dionisio Joao-Dionisio merged commit e3e67c8 into scipopt:master Jan 22, 2026
3 checks passed
@Zeroto521 Zeroto521 deleted the expr/next branch January 22, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants