Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track changes in PyPy behavior introduced in 7.3.14 #3087

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pyomo/core/tests/unit/test_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import functools
import pickle
import platform
import sys
import types

import pyomo.common.unittest as unittest
Expand All @@ -37,6 +39,9 @@
from pyomo.environ import ConcreteModel, Var


is_pypy = platform.python_implementation().lower().startswith("pypy")


def _init_scalar(m):
return 1

Expand Down Expand Up @@ -561,12 +566,20 @@ def test_no_argspec(self):
self.assertFalse(a.contains_indices())
self.assertEqual(a('111', 2), 7)

# Special case: getfullargspec fails on int, so we assume it is
# always an IndexedCallInitializer
# Special case: getfullargspec fails for int under CPython and
# PyPy<7.3.14, so we assume it is an IndexedCallInitializer.
basetwo = functools.partial(int, '101', base=2)
a = Initializer(basetwo)
self.assertIs(type(a), IndexedCallInitializer)
self.assertFalse(a.constant())
if is_pypy and sys.pypy_version_info[:3] >= (7, 3, 14):
# PyPy behavior diverged from CPython in 7.3.14. Arguably
# this is "more correct", so we will allow the difference to
# persist through Pyomo's Initializer handling (and not
# special case it there)
self.assertIs(type(a), ScalarCallInitializer)
self.assertTrue(a.constant())
else:
self.assertIs(type(a), IndexedCallInitializer)
self.assertFalse(a.constant())
self.assertFalse(a.verified)
self.assertFalse(a.contains_indices())
# but this is not callable, as int won't accept the 'model'
Expand Down
4 changes: 2 additions & 2 deletions pyomo/core/tests/unit/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)


using_pypy = platform.python_implementation() == "PyPy"
is_pypy = platform.python_implementation().lower().startswith("pypy")


def obj_rule(model):
Expand Down Expand Up @@ -322,7 +322,7 @@ def rule2(model, i):
model.con = Constraint(rule=rule1)
model.con2 = Constraint(model.a, rule=rule2)
instance = model.create_instance()
if using_pypy:
if is_pypy:
str_ = pickle.dumps(instance)
tmp_ = pickle.loads(str_)
else:
Expand Down