Repository navigation
Replace SCIP constant classes with IntEnum and IntFlag - #1286
Conversation
|
Thank you @jonathanberthias! A couple of things:
|
|
Thanks for the review @Joao-Dionisio! Indeed I had missed a few spots, should be better now 🤞 |
|
Thank you @jonathanberthias! I took the liberty of changing the code a bit, because it was inconsistent across Python versions, regarding the output. from enum import Enum, Flag, IntEnum, IntFlag
def _format(self, spec):
return str(self) if not spec else int.__format__(self, spec)
class _ScipEnum(IntEnum):
__str__ = Enum.__str__
__format__ = _format
class _ScipFlag(IntFlag):
__str__ = Flag.__str__
__format__ = _format
class PY_SCIP_STAGE(_ScipEnum): ...
class PY_SCIP_EVENTTYPE(_ScipFlag): ...Let me know if you're alright with this, please :) I also added stubs to the plugins. |
This is a great idea! I guess this is what you meant here, I didn't think of the string representation 🤦 I was hesitant to type the plugins in case some users test types exactly, but I guess the same applies to all methods that return enum members now so it's the right call I would say. Very nice job 🎉 |
Joao-Dionisio
left a comment
There was a problem hiding this comment.
Thank you @jonathanberthias , and very nice job to you too as well!!
SCIP constants are currently exposed as plain integers grouped in classes. This prevents type checkers from distinguishing different constant families and leaves enum-related methods incompletely typed.
This PR replaces those classes with standard-library
IntEnumandIntFlagclasses, usingIntFlagfor event and timing masks. It updates the stubs, converts enum-valued getters to return enum members, and adjusts the existing tests.Stage and event names now use
.namedirectly.StageNamesandEventNamesremain available with integer keys for backward compatibility.Fixes #1275.