-
Notifications
You must be signed in to change notification settings - Fork 227
Open
Description
Description
The binary_var_list method in the docplex.mp.model API has an incorrect type annotation for the name parameter.
Current signature:
def binary_var_list(self, keys, lb=None, ub=None, name: type[str] = str, key_format=None):The annotation type[str] suggests that the function expects the str class (a type), but according to the documentation and actual behavior, name should accept either:
- a string (e.g., "x")
- a function that generates names.
The default value str is used as a callable to convert keys to strings, which is valid, but the type hint does not reflect this.
Impact
Static type checkers incorrectly flag valid code like:
from docplex.mp.model import Model
model = Model(name="my example problem")
x = model.binary_var_list([1, 3], name="x")Users must resort to # type: ignore or cast hacks.
Suggested fix
Change the function signature to
def binary_var_list(self, keys, lb=None, ub=None, name: str | Callable[..., str] = str, key_format=None):Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels